ResourceUrlEncodingFilter throws StringIndexOutOfBoundsException in tests #29933
Labels
in: test
Issues in the test module
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: regression
A bug that is also a regression
Milestone
Affects: 6.0.4
After adding a FilterRegistrationBean into my project, I swapped from MockMvcBuilder to Spring Boots
@AutoConfigureMockMvc
to have that filter applied in tests. That project also uses Thymeleaf so a ResourceUrlEncodingFilter is added as well by Spring Boot.A existing test started breaking. It tested a
@RequestMapping("")
controller, which causedResourceUrlEncodingFilter
to throw aLookupPathIndexException
[1] because the behaviour changed from requestUri returing""
instead of"/"
.When an
ExceptionHandler
also callsHttpServletResponse#encodeURL
(rendering a HTML error page with @{...} from thymeleaf),indexLookupPath
will already have the value of -1 and instead will throw aStringIndexOutOfBoundsException
in resolveUrlPath [2].Here's a project demonstrating the problem as well as the differences between
MockMvcBuilder
withoutResourceUrlEncodingFilter
,MockMvcBuilder
withResourceUrlEncodingFilter
and@AutoConfigureMockMvc
:https://github.com/schosin/AutoConfigureMockMvcErrorApplication
To see the
StringIndexOutOfBoundsException
, enable the profile errorhandling in application.properties.[1] LookupPathIndexException
[2] IndexOutOfBoundsException
The text was updated successfully, but these errors were encountered: