Skip to content

Commit

Permalink
Issue google#745: PathInfo not encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 9, 2014
1 parent 2b4dd16 commit 41c126f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
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;
Expand Down Expand Up @@ -216,6 +218,12 @@ public String getPathInfo() {
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public final void testPathInfoWithServletStyleMatching() throws IOException, Ser
"/.../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,
Expand Down Expand Up @@ -228,6 +232,11 @@ public final void testPathInfoWithRegexMatching() throws IOException, ServletExc
// 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,
Expand Down

0 comments on commit 41c126f

Please sign in to comment.