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/e6c24a19 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e6c24a19 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e6c24a19 Branch: refs/heads/5299-ajax-strategy Commit: e6c24a19f0ada846445cbc9a3d87a0a37617db84 Parents: 2e2c4ba 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:42:55 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/e6c24a19/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 ecd0f22..0581076 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 @@ -205,7 +205,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/e6c24a19/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/e6c24a19/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 596163e..11f6b47 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) {