Updated Branches: refs/heads/wicket-1.5.x b60561d3d -> 4d6b76dee
WICKET-4877 semicolon (;) starts segments if no slash is present Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/4d6b76de Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/4d6b76de Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/4d6b76de Branch: refs/heads/wicket-1.5.x Commit: 4d6b76dee31f232cd4634db06aa463afd8b4c448 Parents: b60561d Author: svenmeier <[email protected]> Authored: Thu Nov 22 14:58:31 2012 +0100 Committer: svenmeier <[email protected]> Committed: Thu Nov 22 14:58:31 2012 +0100 ---------------------------------------------------------------------- .../main/java/org/apache/wicket/request/Url.java | 64 ++++++++------- .../java/org/apache/wicket/request/UrlTest.java | 17 +++- 2 files changed, 50 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/4d6b76de/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 8393d7d..077f167 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 @@ -79,8 +79,7 @@ public class Url implements Serializable * * @author igor */ - public static enum StringMode - { + public static enum StringMode { /** local urls are rendered without the host name */ LOCAL, /** @@ -169,8 +168,11 @@ public class Url implements Serializable final String afterProto = absoluteUrl.substring(protocolAt + 3); final String hostAndPort; - final int relativeAt = afterProto.indexOf('/'); - + int relativeAt = afterProto.indexOf('/'); + if (relativeAt == -1) + { + relativeAt = afterProto.indexOf(';'); + } if (relativeAt == -1) { relativeUrl = ""; @@ -987,7 +989,8 @@ public class Url implements Serializable getSegments().remove(getSegments().size() - 1); } - // remove leading './' (current folder) and empty segments, process any ../ segments from the + // remove leading './' (current folder) and empty segments, process any ../ segments from +// the // relative url while (!relative.getSegments().isEmpty()) { @@ -1154,39 +1157,44 @@ public class Url implements Serializable { return getQueryString(getCharset()); } - - + + /** - * Try to reduce url by eliminating '..' and '.' from the path where appropriate - * (this is somehow similar to {@link java.io.File#getCanonicalPath()}). - * Either by different / unexpected browser behavior or by malicious attacks it - * can happen that these kind of redundant urls are processed by wicket. These urls - * can cause some trouble when mapping the request. - * <p/> + * Try to reduce url by eliminating '..' and '.' from the path where appropriate (this is + * somehow similar to {@link java.io.File#getCanonicalPath()}). Either by different / unexpected + * browser behavior or by malicious attacks it can happen that these kind of redundant urls are + * processed by wicket. These urls can cause some trouble when mapping the request. + * <p/> * <strong>example:</strong> * * the url * - * <pre> /example/..;jsessionid=234792?0</pre> + * <pre> + * /example/..;jsessionid=234792?0 + * </pre> * - * will not get normalized by the browser due to the ';jsessionid' string that - * gets appended by the servlet container. After wicket strips the - * jsessionid part the resulting internal url will be + * will not get normalized by the browser due to the ';jsessionid' string that gets appended by + * the servlet container. After wicket strips the jsessionid part the resulting internal url + * will be * - * <pre> /example/..</pre> + * <pre> + * /example/.. + * </pre> * * instead of * - * <pre> /</pre> + * <pre> + * / + * </pre> * * <p/> * - * This code correlates to - * <a href="https://issues.apache.org/jira/browse/WICKET-4303">WICKET-4303</a> - * + * This code correlates to <a + * href="https://issues.apache.org/jira/browse/WICKET-4303">WICKET-4303</a> + * * @param url - * unprocessed url - * + * unprocessed url + * * @return canonical url */ public Url canonical() @@ -1194,18 +1202,18 @@ public class Url implements Serializable Url url = new Url(this); url.segments.clear(); - for (int i = 0; i < this.segments.size(); i++) + for (int i = 0; i < segments.size(); i++) { - final String segment = this.segments.get(i); + final String segment = segments.get(i); - // drop '.' from path + // drop '.' from path if (".".equals(segment)) { continue; } // skip segment if following segment is a '..' - if ((i + 1) < this.segments.size() && "..".equals(this.segments.get(i + 1))) + if ((i + 1) < segments.size() && "..".equals(segments.get(i + 1))) { i++; continue; http://git-wip-us.apache.org/repos/asf/wicket/blob/4d6b76de/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java ---------------------------------------------------------------------- diff --git a/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java b/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java index 527d4a8..54200d6 100644 --- a/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java +++ b/wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java @@ -224,6 +224,18 @@ public class UrlTest extends Assert } /** + * https://issues.apache.org/jira/browse/WICKET-4877 + */ + @Test + public void testParse15() + { + String s = "http://localhost:56704;jsessionid=8kxeo3reannw1qjtxgkju8yiu"; + Url url = Url.parse(s); + assertEquals(Integer.valueOf(56704), url.getPort()); + checkSegments(url, ";jsessionid=8kxeo3reannw1qjtxgkju8yiu"); + } + + /** * */ @Test @@ -764,9 +776,8 @@ public class UrlTest extends Assert } /** - * https://issues.apache.org/jira/browse/WICKET-4387 - * Parse uri with '://' in it should consider it as absolute only if there are - * no slashes earlier in the string. + * https://issues.apache.org/jira/browse/WICKET-4387 Parse uri with '://' in it should consider + * it as absolute only if there are no slashes earlier in the string. */ @Test public void parseHttpSlashSlashColon()
