Tentative fix for string index out of bounds exception in issue #560
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1299 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
index e433436..184ce36 100755
--- a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
+++ b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
@@ -202,9 +202,9 @@
@Override
public String getPathInfo() {
if (!isPathInfoComputed()) {
- final int servletPathLength = getServletPath().length();
- pathInfo = getRequestURI().substring(getContextPath().length()).replaceAll("[/]{2,}", "/")
- .substring(servletPathLength);
+ 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