You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jb...@apache.org on 2007/08/23 16:10:35 UTC
svn commit: r569002 - in /wicket/trunk/jdk-1.4/wicket/src:
main/java/org/apache/wicket/protocol/http/ test/java/
test/java/org/apache/wicket/protocol/http/
Author: jbq
Date: Thu Aug 23 07:10:34 2007
New Revision: 569002
URL: http://svn.apache.org/viewvc?rev=569002&view=rev
Log:
WICKET-702 MockWebApplication doesn't redirect properly to mounted pages under RestartResponseAtInterceptPageException
Use a cross-platform way to remove ".." in the path
Added:
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java (with props)
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
wicket/trunk/jdk-1.4/wicket/src/test/java/log4j.properties
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java?rev=569002&r1=569001&r2=569002&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockHttpServletRequest.java Thu Aug 23 07:10:34 2007
@@ -23,7 +23,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.Principal;
@@ -1294,18 +1293,11 @@
// We need to absolutize the redirect URL as we are not as smart as a web-browser (WICKET-702)
url = getContextPath() + getServletPath() + "/" + redirect;
- try
- {
- // Remove occurences of ".." from the path
- url = new File(url).getCanonicalPath();
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
+ // Remove occurences of ".." from the path
+ url = RequestUtils.removeDoubleDots(url);
log.info("Redirecting to " + url);
}
-
+
/**
* Helper method to create some default headers for the request
*/
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java?rev=569002&r1=569001&r2=569002&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java Thu Aug 23 07:10:34 2007
@@ -18,7 +18,11 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.value.ValueMap;
/**
@@ -59,6 +63,36 @@
// Should never happen
}
}
+ }
+
+ /**
+ * Remove occurences of ".." from the path
+ * @param path
+ * @return
+ */
+ static String removeDoubleDots(String path)
+ {
+ String[] components = path.split("/");
+ List newcomponents = new ArrayList(Arrays.asList(components));
+
+ for (int i=0; i<components.length; i++)
+ {
+ if (i<components.length-1)
+ {
+ // Verify for a ".." component at next iteration
+ if (components[i].length() > 0 && components[i+1].equals(".."))
+ {
+ newcomponents.remove(i);
+ newcomponents.remove(i);
+ // Skip the ".." component
+ i++;
+ }
+ }
+ }
+ String newpath = Strings.join("/", (String[])newcomponents.toArray(new String[0]));
+ if (path.endsWith("/"))
+ return newpath + "/";
+ return newpath;
}
/**
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/log4j.properties
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/log4j.properties?rev=569002&r1=569001&r2=569002&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/log4j.properties (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/log4j.properties Thu Aug 23 07:10:34 2007
@@ -10,6 +10,7 @@
# why there are stacktraces in the test output. You can turn it
# down if you need to when testing, but don't check it in. (eelco)
log4j.logger.org.apache.wicket=FATAL
+log4j.logger.org.apache.wicket.protocol.http.MockHttpServletRequest=INFO
#log4j.logger.org.apache.wicket.resource=FATAL
#log4j.logger.org.apache.wicket.Localizer=FATAL
Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java?rev=569002&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java Thu Aug 23 07:10:34 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.protocol.http;
+
+import junit.framework.TestCase;
+
+public class RequestUtilsTest extends TestCase
+{
+ public void testDoubleDotsMiddle() {
+ assertEquals("/a/b", RequestUtils.removeDoubleDots("/a/b/../b"));
+ assertEquals("a/b", RequestUtils.removeDoubleDots("a/b/../b"));
+ assertEquals("a/b/", RequestUtils.removeDoubleDots("a/b/../b/"));
+ }
+ public void testDoubleDotsEnd() {
+ assertEquals("/a/b", RequestUtils.removeDoubleDots("/a/b/c/.."));
+ assertEquals("a/b", RequestUtils.removeDoubleDots("a/b/c/.."));
+ }
+ public void testDoubleDotsStart() {
+ assertEquals("/../a/b", RequestUtils.removeDoubleDots("/../a/b"));
+ assertEquals("../a/b", RequestUtils.removeDoubleDots("../a/b"));
+ }
+ public void testEmptyDoubleDots() {
+ assertEquals("", RequestUtils.removeDoubleDots(""));
+ }
+ public void testOneDoubleDots() {
+ assertEquals("..", RequestUtils.removeDoubleDots(".."));
+ assertEquals("../", RequestUtils.removeDoubleDots("../"));
+ assertEquals("/..", RequestUtils.removeDoubleDots("/.."));
+ }
+}
Propchange: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
------------------------------------------------------------------------------
svn:keywords = Id