aboutsummaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorSam Berlin <sberlin@gmail.com>2014-10-09 20:42:45 -0400
committerSam Berlin <sberlin@gmail.com>2014-10-09 20:42:45 -0400
commitc040e3797e30f4b52df1a10637259b2e08f1c0de (patch)
tree8aa49ee9ce6205fb7cd8965f42f9d8ddb80fb4d9 /extensions
parent2b4dd1617e61fac3869381e9e7728b488badc5e2 (diff)
parent41c126f99d6309886a0ded2ac729033d755e1593 (diff)
downloadguice-c040e3797e30f4b52df1a10637259b2e08f1c0de.tar.gz
Merge pull request #860 from cstamas/issue-745-pathInfo-decode
Issue #745: PathInfo not encoded
Diffstat (limited to 'extensions')
-rw-r--r--extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java8
-rw-r--r--extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java9
2 files changed, 17 insertions, 0 deletions
diff --git a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
index 3b5aea88..11328edb 100644
--- a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
+++ b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
@@ -26,6 +26,8 @@ import com.google.inject.spi.ProviderInstanceBinding;
import com.google.inject.spi.ProviderWithExtensionVisitor;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -216,6 +218,12 @@ class ServletDefinition implements ProviderWithExtensionVisitor<ServletDefinitio
// then pathinfo is null.
if (pathInfo.isEmpty() && servletPathLength > 0) {
pathInfo = null;
+ } else {
+ try {
+ pathInfo = new URI(pathInfo).getPath();
+ } catch (URISyntaxException e) {
+ // ugh, just leave it alone then
+ }
}
} else {
pathInfo = null; // we know nothing additional about the URI.
diff --git a/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java b/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
index 5509a6c5..c89834fc 100644
--- a/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
@@ -133,6 +133,10 @@ public class ServletDefinitionPathsTest extends TestCase {
"/.../h.thing");
pathInfoWithServletStyleMatching("/path/my/h.thing", "/path", "*.thing", null, "/my/h.thing");
+ // Encoded URLs
+ pathInfoWithServletStyleMatching("/path/index%2B.html", "/path", "/*", "/index+.html", "");
+ pathInfoWithServletStyleMatching("/path/a%20file%20with%20spaces%20in%20name.html", "/path", "/*", "/a file with spaces in name.html", "");
+ pathInfoWithServletStyleMatching("/path/Tam%C3%A1s%20nem%20m%C3%A1s.html", "/path", "/*", "/Tamás nem más.html", "");
}
private void pathInfoWithServletStyleMatching(final String requestUri, final String contextPath,
@@ -228,6 +232,11 @@ public class ServletDefinitionPathsTest extends TestCase {
// path
pathInfoWithRegexMatching("/path/test.com/com.test.MyServletModule", "", "/path/[^/]+/(.*)",
"com.test.MyServletModule", "/path/test.com/com.test.MyServletModule");
+
+ // Encoded URLs
+ pathInfoWithRegexMatching("/path/index%2B.html", "/path", "/(.)*", "/index+.html", "");
+ pathInfoWithRegexMatching("/path/a%20file%20with%20spaces%20in%20name.html", "/path", "/(.)*", "/a file with spaces in name.html", "");
+ pathInfoWithRegexMatching("/path/Tam%C3%A1s%20nem%20m%C3%A1s.html", "/path", "/(.)*", "/Tamás nem más.html", "");
}
public final void pathInfoWithRegexMatching(final String requestUri, final String contextPath,