diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-12-21 13:57:28 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-12-21 13:57:28 +0100 |
commit | c2c68ac0d453944ef81d04f442077f741d350011 (patch) | |
tree | 767a5ecd088cabeb3d675a0cfb406ebcf57c34be /jdisc_core | |
parent | 398b5e3b48874c77cc74c7db41628d1440cf6b0e (diff) |
Use the rawPath, not the URL-decoded path, of the URI
Diffstat (limited to 'jdisc_core')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java | 4 | ||||
-rw-r--r-- | jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java index edac56c72dd..058fa1f7772 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java @@ -98,7 +98,7 @@ public class UriPattern implements Comparable<UriPattern> { if (port > 0 && port != uri.getPort()) return null; - String uriPath = uri.getPath() == null ? "/" : uri.getPath(); + String uriPath = uri.getRawPath() == null ? "/" : uri.getRawPath(); GlobPattern.Match pathMatch = path.match(uriPath, 1); // Don't match the leading '/'. if (pathMatch == null) return null; @@ -123,7 +123,7 @@ public class UriPattern implements Comparable<UriPattern> { @Override public boolean equals(Object obj) { - return obj instanceof UriPattern && pattern.equals(((UriPattern)obj).pattern); + return obj instanceof UriPattern && pattern.equals(((UriPattern) obj).pattern); } @Override diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java index da48503729d..0ea82508f06 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java @@ -271,6 +271,17 @@ public class UriPatternTestCase { assertMatch(httpsPattern, "http://host:443/path", NO_GROUPS); } + @Test + public void requireThatUrlEncodingIsNotDoneForPath() { + UriPattern encodedSlashPattern = new UriPattern("http://host:80/one%2Fpath"); + assertMatch(encodedSlashPattern, "http://host:80/one%2Fpath", NO_GROUPS); + assertNotMatch(encodedSlashPattern, "http://host:80/one/path"); + + UriPattern actualSlashPattern = new UriPattern("http://host:80/two/paths"); + assertNotMatch(actualSlashPattern, "http://host:80/two%2Fpaths"); + assertMatch(actualSlashPattern, "http://host:80/two/paths", NO_GROUPS); + } + private static void assertIllegalPattern(String uri) { try { new UriPattern(uri); |