Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Fix issue 745 Properly decode URL paths #8

Merged
merged 1 commit into from
Feb 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -217,6 +219,14 @@ public String getPathInfo() {
pathInfo = null;
}

if (pathInfo != null) {
try {
pathInfo = new URI(pathInfo).getPath();
} catch (URISyntaxException e) {
// ugh, just leave it alone then
}
}

pathInfoComputed = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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 @@ -227,6 +231,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