Fix external issue 372 -- only scrub the pathInfo if the servletPath actually
began it (not if it just happens to be longer than the servlet path).
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=64723867
diff --git a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
index 1111fde..b09d283 100644
--- a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
+++ b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
@@ -205,18 +205,19 @@
@Override
public String getPathInfo() {
if (!isPathInfoComputed()) {
- int servletPathLength = getServletPath().length();
- pathInfo = getRequestURI().substring(getContextPath().length())
- .replaceAll("[/]{2,}", "/");
- pathInfo = pathInfo.length() > servletPathLength
- ? pathInfo.substring(servletPathLength) : null;
-
- // Corner case: when servlet path and request path match exactly (without trailing '/'),
- // then pathinfo is null
- if ("".equals(pathInfo) && servletPathLength != 0) {
- pathInfo = null;
+ String servletPath = getServletPath();
+ int servletPathLength = servletPath.length();
+ String requestUri = getRequestURI();
+ pathInfo = requestUri.substring(getContextPath().length()).replaceAll("[/]{2,}", "/");
+ // See: http://code.google.com/p/google-guice/issues/detail?id=372
+ if (pathInfo.startsWith(servletPath)) {
+ pathInfo = pathInfo.substring(servletPathLength);
+ // Corner case: when servlet path & request path match exactly (without trailing '/'),
+ // then pathinfo is null.
+ if (pathInfo.isEmpty() && servletPathLength > 0) {
+ pathInfo = null;
+ }
}
-
pathInfoComputed = true;
}
diff --git a/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java b/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
index a5ac841..91226fe 100644
--- a/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/ServletDefinitionPathsTest.java
@@ -124,6 +124,10 @@
"/thing");
pathInfoWithServletStyleMatching("/path/thing", "/path", "/thing/*", null, "/thing");
+ // see external issue 372
+ pathInfoWithServletStyleMatching("/path/some/path/of.jsp", "/path", "/thing/*",
+ "/some/path/of.jsp", "/some/path/of.jsp");
+
// *.xx style mapping
pathInfoWithServletStyleMatching("/path/thing.thing", "/path", "*.thing", null, "/thing.thing");
pathInfoWithServletStyleMatching("/path///h.thing", "/path", "*.thing", null, "/h.thing");