Fix wrong reference in UrlPathHelper.removeSemicolonContentInternal()

This commit also changes to short-circuit when `slashIndex` is -1.
This commit is contained in:
izeye 2020-11-09 20:56:23 +09:00 committed by Juergen Hoeller
parent 2497d4285f
commit 0c347769a2
2 changed files with 5 additions and 2 deletions

View File

@ -618,9 +618,9 @@ public class UrlPathHelper {
}
StringBuilder sb = new StringBuilder(requestUri);
while (semicolonIndex != -1) {
int slashIndex = requestUri.indexOf('/', semicolonIndex + 1);
int slashIndex = sb.indexOf("/", semicolonIndex + 1);
if (slashIndex == -1) {
slashIndex = sb.length();
return sb.substring(0, semicolonIndex);
}
sb.delete(semicolonIndex, slashIndex);
semicolonIndex = sb.indexOf(";", semicolonIndex);

View File

@ -115,6 +115,9 @@ public class UrlPathHelperTests {
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R");
assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar");
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R/baz;test");
assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar/baz");
// SPR-13455
request.setRequestURI("/foo/;test/1");
request.setServletPath("/foo/1");