Author: frankbille
Date: Wed Oct 25 16:18:02 2006
New Revision: 467806

URL: http://svn.apache.org/viewvc?view=rev&rev=467806
Log:
WICKET-16: Make sure that bookmarkable urls for classes containing non-ascii 
characters is encoded properly.

Added:
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/WebRequestCodingStrategyTest.java
Modified:
    incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java

Modified: incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml?view=diff&rev=467806&r1=467805&r2=467806
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml 
(original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml Wed Oct 
25 16:18:02 2006
@@ -15,6 +15,7 @@
     <release version="1.3" date="tbd" description="Wicket 1.3">
        </release>
        <release version="1.2.3" description="Wicket 1.2.3">
+               <action type="fix" dev="Frank Bille Jensen" 
issue="WICKET-16">Make sure that bookmarkable urls for classes containing 
non-ascii characters is encoded properly.</action>
                <action type="add" dev="Eelco Hillenius">Added method protected 
void onDisabled(final ComponentTag tag) to FormComponent, which is called 
during rendering when the component is disabled. By default, an 
disabled="disabled" attribute is added, but clients may override this 
method.</action>
                <action type="add" dev="Eelco Hillenius">Made synchronization 
timeout configurable on an application level. Later, we might add more fine 
grained control.</action>
                <action type="add" dev="Eelco Hillenius">Implemented optional 
interface for initializers: IDestroyer that may be implemented by initializers 
to clear up stuff when the application is shut down. Wicket's JMX code uses 
this to clean up the JMX beans it registered on application shutdown.</action>

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java?view=diff&rev=467806&r1=467805&r2=467806
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
 Wed Oct 25 16:18:02 2006
@@ -563,7 +563,25 @@
 
 
                        // Add <page-map-name>:<bookmarkable-page-class>
-                       url.append(pageMapName + Component.PATH_SEPARATOR + 
pageClass.getName());
+                       String pageClassName = pageClass.getName();
+                       /*
+                        * Encode the url so it is correct even for class names 
containing
+                        * non ASCII characters, like ä, æ, ø, å etc.
+                        * 
+                        * The reason for this is that when redirecting to these
+                        * bookmarkable pages, we need to have the url encoded 
correctly
+                        * because we can't rely on the browser to interpret 
the unencoded
+                        * url correctly.
+                        */
+                       try
+                       {
+                               pageClassName = 
URLEncoder.encode(pageClassName, "UTF-8");
+                       }
+                       catch (UnsupportedEncodingException e)
+                       {
+                               throw new RuntimeException(e);
+                       }
+                       url.append(pageMapName + Component.PATH_SEPARATOR + 
pageClassName);
                }
 
                // Get page parameters

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/N%C3%B6n%C3%85sciiP%C3%A4ge.html?view=auto&rev=467806
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
 Wed Oct 25 16:18:02 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+
+</body>
+</html>
\ No newline at end of file

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/N%C3%B8n%C3%85sciiP%C3%A4ge.java?view=auto&rev=467806
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
 Wed Oct 25 16:18:02 2006
@@ -0,0 +1,31 @@
+/*
+ * $Id: org.eclipse.jdt.ui.prefs 5004 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 
2006) eelco12 $
+ * $Revision: 5004 $
+ * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
+ * 
+ * 
==============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package wicket.protocol.http.request;
+
+import wicket.markup.html.WebPage;
+
+/**
+ * Mock page for the testEncode_nonAsciiClassName test.
+ * 
+ * @author frankbille
+ */
+public class NønÅsciiPäge extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+}

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/WebRequestCodingStrategyTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/WebRequestCodingStrategyTest.java?view=auto&rev=467806
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/WebRequestCodingStrategyTest.java
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/request/WebRequestCodingStrategyTest.java
 Wed Oct 25 16:18:02 2006
@@ -0,0 +1,80 @@
+/*
+ * $Id: org.eclipse.jdt.ui.prefs 5004 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 
2006) eelco12 $
+ * $Revision: 5004 $
+ * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
+ * 
+ * 
==============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package wicket.protocol.http.request;
+
+import wicket.RequestCycle;
+import wicket.WicketTestCase;
+import wicket.request.target.component.BookmarkablePageRequestTarget;
+import wicket.request.target.component.IBookmarkablePageRequestTarget;
+import wicket.resource.DummyPage;
+
+/**
+ * Test of WebRequestCodingStrategy.
+ * 
+ * @author frankbille
+ */
+public class WebRequestCodingStrategyTest extends WicketTestCase
+{
+       private boolean executed;
+
+       /**
+        * Construct.
+        */
+       public WebRequestCodingStrategyTest()
+       {
+               super("Test of WebRequestCodingStrategy");
+       }
+
+       /**
+        * Test that the encoding generates correct encoded urls even for class
+        * names containing non ASCII characters, like ä, æ, ø, å etc.
+        * 
+        * See description in
+        * [EMAIL PROTECTED] WebRequestCodingStrategy#encode(RequestCycle, 
IBookmarkablePageRequestTarget)}
+        * for further information.
+        */
+       public void testEncode__bookmarkablePage_nonAsciiClassNames()
+       {
+               application.setupRequestAndResponse();
+               RequestCycle requestCycle = application.createRequestCycle();
+               application.setHomePage(DummyPage.class);
+
+               executed = false;
+               WebRequestCodingStrategy codingStrategy = new 
WebRequestCodingStrategy()
+               {
+                       protected CharSequence encode(RequestCycle requestCycle,
+                                       IBookmarkablePageRequestTarget 
requestTarget)
+                       {
+                               executed = true;
+                               return super.encode(requestCycle, 
requestTarget);
+                       }
+               };
+
+               CharSequence url = codingStrategy.encode(requestCycle, new 
BookmarkablePageRequestTarget(
+                               NønÅsciiPäge.class));
+
+               assertTrue(executed);
+
+               assertNotNull(url);
+
+               assertTrue(url.toString().endsWith(
+                               
"wicket.protocol.http.request.N%C3%B8n%C3%85sciiP%C3%A4ge"));
+       }
+
+}


Reply via email to