frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Servlet regex path dispatching is inflexible for getServletPath() #376

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We need to make it so that arbitrary matching groups can be supported. For 
example, currently it's 
awkward to match this set of paths:
   /foo/baz/show
   /foo/bar/show
   /foo/quux/show

The fix is to change the matcher to use end(1) rather than start(1).
  http://code.google.com/p/google-guice/source/diff?
spec=svn930&r=930&format=side&path=/trunk/servlet/src/com/google/inject/servlet/
UriPattern
Type.java

Original issue reported on code.google.com by limpbizkit on 21 May 2009 at 11:31

GoogleCodeExporter commented 9 years ago
The underlying problem can also cause an exception when getServletPath() is 
called.

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1949)
    at
com.google.inject.servlet.UriPatternType$RegexUriPatternMatcher.extractPath(UriP
atternType.java:116)
    at com.google.inject.servlet.ServletDefinition$2.computePath(ServletDefinition.java:204)
    at
com.google.inject.servlet.ServletDefinition$2.getServletPath(ServletDefinition.j
ava:190)
    at com.google.foo.bar.SomeServlet.doGet(ShortLaunchUrlServlet.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:216)
    at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:141)
    at
com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.
java:93)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:63)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.someFilter.doFilter(LaunchCalModule.java:527)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:129)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
    at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.j
ava:59)
    at
com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.j
ava:122)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)

The servlet in question was registered with the following regex:
"^/((?:index\\.php/)?something/view/)?(\\d+)$"

and the request was of the form http://server/1234

Original comment by grandche...@gmail.com on 22 May 2009 at 12:20

GoogleCodeExporter commented 9 years ago
Dhanji, could you take a look into this? I think it's an easy fix...

Original comment by limpbizkit on 22 Jun 2009 at 2:22

GoogleCodeExporter commented 9 years ago
Yep I'll patch this shortly.

Original comment by dha...@gmail.com on 22 Jun 2009 at 11:38

GoogleCodeExporter commented 9 years ago
Has this patch been lost? I am seeing the same issue as mentioned in comment #1 
for the regexp "^/(?!(css|img|js)).*" (with Guice 3.0).

Original comment by th...@ginkel.com on 24 May 2012 at 9:51

GoogleCodeExporter commented 9 years ago
Same for "/api/auth(/.*[^(\\.jsp)])?$"
(with Guice 3.0)

Original comment by rod...@alukhanov.ru on 28 Jan 2013 at 12:50