Updated Branches:
  refs/heads/wicket-6.x 7b8785cde -> ee075afab

WICKET-5287 NumberFormatException when parsing the port from Requests with 
invalid URIs


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ee075afa
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ee075afa
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ee075afa

Branch: refs/heads/wicket-6.x
Commit: ee075afab34b503b65270627621fff8b00898e24
Parents: 7b8785c
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Authored: Thu Aug 8 14:42:55 2013 +0200
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Thu Aug 8 14:43:12 2013 +0200

----------------------------------------------------------------------
 .../protocol/http/servlet/ServletWebRequest.java   |  2 +-
 .../http/servlet/ServletWebRequestTest.java        | 15 +++++++++++++++
 .../main/java/org/apache/wicket/request/Url.java   | 17 ++++++++++++++++-
 3 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/ee075afa/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
index 24947bb..e97113f 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
@@ -206,7 +206,7 @@ public class ServletWebRequest extends WebRequest
                        }
                }
 
-               return setParameters(Url.parse(url.toString(), getCharset()));
+               return setParameters(Url.parse(url.toString(), getCharset(), 
false));
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/ee075afa/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
index f974a06..965dcd8 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
@@ -191,6 +191,21 @@ public class ServletWebRequestTest extends Assert
                assertEquals("any/source/of/error", errorClientUrl.toString());
        }
 
+       /**
+        * WICKET-5287
+        */
+       @Test
+       public void parseUrlWhichLooksLikeFullInItsContextRelativePart()
+       {
+               String filterPath = "filterPath";
+               MockHttpServletRequest httpRequest = new 
MockHttpServletRequest(null, null, null);
+               String looksLikeFullUrl = "/foo://:/";
+               httpRequest.setURL("http://localhost"; + '/' + 
httpRequest.getContextPath() + '/' + filterPath + looksLikeFullUrl);
+
+               ServletWebRequest webRequest = new 
ServletWebRequest(httpRequest, filterPath);
+               assertEquals(looksLikeFullUrl, 
webRequest.getClientUrl().toString());
+       }
+
        private static class CustomRequestPage extends WebPage implements 
IMarkupResourceStreamProvider
        {
                private static final long serialVersionUID = 1L;

http://git-wip-us.apache.org/repos/asf/wicket/blob/ee075afa/wicket-request/src/main/java/org/apache/wicket/request/Url.java
----------------------------------------------------------------------
diff --git a/wicket-request/src/main/java/org/apache/wicket/request/Url.java 
b/wicket-request/src/main/java/org/apache/wicket/request/Url.java
index ab70446..c285c51 100755
--- a/wicket-request/src/main/java/org/apache/wicket/request/Url.java
+++ b/wicket-request/src/main/java/org/apache/wicket/request/Url.java
@@ -202,6 +202,21 @@ public class Url implements Serializable
         */
        public static Url parse(CharSequence _url, Charset charset)
        {
+               return parse(_url, charset, true);
+       }
+
+       /**
+        * Parses the given URL string.
+        *
+        * @param _url
+        *            absolute or relative url with query string
+        * @param charset
+        * @param isFullHint
+        *            a hint whether to try to parse the protocol, host and 
port part of the url
+        * @return Url object
+        */
+       public static Url parse(CharSequence _url, Charset charset, boolean 
isFullHint)
+       {
                Args.notNull(_url, "_url");
 
                final Url result = new Url(charset);
@@ -237,7 +252,7 @@ public class Url implements Serializable
                boolean protocolLess = absoluteUrl.startsWith("//");
                final boolean isFull = (protocolAt > 1 && (protocolAt < 
idxOfFirstSlash)) || protocolLess;
 
-               if (isFull)
+               if (isFull && isFullHint)
                {
                        if (protocolLess == false)
                        {

Reply via email to