Skip to content

Commit 0c34776

Browse files
izeyejhoeller
authored andcommitted
Fix wrong reference in UrlPathHelper.removeSemicolonContentInternal()
This commit also changes to short-circuit when `slashIndex` is -1.
1 parent 2497d42 commit 0c34776

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,9 @@ private static String removeSemicolonContentInternal(String requestUri) {
618618
}
619619
StringBuilder sb = new StringBuilder(requestUri);
620620
while (semicolonIndex != -1) {
621-
int slashIndex = requestUri.indexOf('/', semicolonIndex + 1);
621+
int slashIndex = sb.indexOf("/", semicolonIndex + 1);
622622
if (slashIndex == -1) {
623-
slashIndex = sb.length();
623+
return sb.substring(0, semicolonIndex);
624624
}
625625
sb.delete(semicolonIndex, slashIndex);
626626
semicolonIndex = sb.indexOf(";", semicolonIndex);

spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public void getRequestRemoveSemicolonContent() {
115115
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R");
116116
assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar");
117117

118+
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R/baz;test");
119+
assertThat(helper.getRequestUri(request)).isEqualTo("/foo/bar/baz");
120+
118121
// SPR-13455
119122
request.setRequestURI("/foo/;test/1");
120123
request.setServletPath("/foo/1");

0 commit comments

Comments
 (0)