Skip to content

Commit

Permalink
issue google#1655: prevent NullPointerException if contextPath is null
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtseebauer committed Nov 17, 2022
1 parent 7e74007 commit 45c1b69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ public String getPathInfo() {
String servletPath = getServletPath();
int servletPathLength = servletPath.length();
String requestUri = getRequestURI();
pathInfo = requestUri.substring(getContextPath().length()).replaceAll("[/]{2,}", "/");
String contextPath = getContextPath();
int contextPathLength = contextPath != null ? contextPath.length() : 0;
pathInfo = requestUri.substring(contextPathLength).replaceAll("[/]{2,}", "/");
// See: https://github.com/google/guice/issues/372
if (pathInfo.startsWith(servletPath)) {
pathInfo = pathInfo.substring(servletPathLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected void service(
// Data-driven test.
public final void testPathInfoWithServletStyleMatching() throws IOException, ServletException {
pathInfoWithServletStyleMatching("/path/index.html", "/path", "/*", "/index.html", "");
pathInfoWithServletStyleMatching("/index.html", null, "/*", "/index.html", "");
pathInfoWithServletStyleMatching(
"/path//hulaboo///index.html", "/path", "/*", "/hulaboo/index.html", "");
pathInfoWithServletStyleMatching("/path/", "/path", "/*", "/", "");
Expand Down

0 comments on commit 45c1b69

Please sign in to comment.