You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by fr...@apache.org on 2006/10/26 01:02:13 UTC

svn commit: r467803 - in /incubator/wicket/trunk/wicket/src: main/java/wicket/protocol/http/request/ test/java/wicket/protocol/http/request/

Author: frankbille
Date: Wed Oct 25 16:02:12 2006
New Revision: 467803

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

Added:
    incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategyTest.java
    incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
    incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
Modified:
    incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategy.java

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategy.java?view=diff&rev=467803&r1=467802&r2=467803
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategy.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategy.java Wed Oct 25 16:02:12 2006
@@ -333,7 +333,26 @@
 
 
 			// 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);
 		}
 
 		// Is it a bookmarkable interface listener?

Added: incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategyTest.java?view=auto&rev=467803
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategyTest.java (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/AbstractWebRequestCodingStrategyTest.java Wed Oct 25 16:02:12 2006
@@ -0,0 +1,73 @@
+/*
+ * $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 AbstractWebRequestCodingStrategy.
+ * 
+ * @author frankbille
+ */
+public class AbstractWebRequestCodingStrategyTest extends WicketTestCase
+{
+	private boolean executed;
+
+	/**
+	 * Test that the encoding generates correct encoded urls even for class
+	 * names containing non ASCII characters, like ä, æ, ø, å etc.
+	 * 
+	 * See description in
+	 * {@link AbstractWebRequestCodingStrategy#encode(RequestCycle, IBookmarkablePageRequestTarget)}
+	 * for further information.
+	 */
+	public void testEncode__bookmarkablePage_nonAsciiClassNames()
+	{
+		application.setupRequestAndResponse();
+		RequestCycle requestCycle = application.createRequestCycle();
+		application.setHomePage(DummyPage.class);
+
+		executed = false;
+		AbstractWebRequestCodingStrategy codingStrategy = new WebRequestCodingStrategy()
+		{
+			@Override
+			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"));
+	}
+
+}

Added: incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/N%C3%B6n%C3%85sciiP%C3%A4ge.html?view=auto&rev=467803
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NönÅsciiPäge.html Wed Oct 25 16:02:12 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/trunk/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/N%C3%B8n%C3%85sciiP%C3%A4ge.java?view=auto&rev=467803
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/request/NønÅsciiPäge.java Wed Oct 25 16:02:12 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;
+}