Skip to content

Commit 6327c60

Browse files
committed
UrlPathHelper.removeJsessionid correctly appends remainder
Closes gh-26079
1 parent 1efcff1 commit 6327c60

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private String removeJsessionid(String requestUri) {
543543
return requestUri;
544544
}
545545
String start = requestUri.substring(0, index);
546-
for (int i = key.length(); i < requestUri.length(); i++) {
546+
for (int i = index + key.length(); i < requestUri.length(); i++) {
547547
char c = requestUri.charAt(i);
548548
if (c == ';' || c == '/') {
549549
return start + requestUri.substring(i);

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,19 @@ public void getRequestRemoveSemicolonContent() throws UnsupportedEncodingExcepti
129129
public void getRequestKeepSemicolonContent() {
130130
helper.setRemoveSemicolonContent(false);
131131

132-
request.setRequestURI("/foo;a=b;c=d");
133-
assertEquals("/foo;a=b;c=d", helper.getRequestUri(request));
134-
135-
request.setRequestURI("/foo;jsessionid=c0o7fszeb1");
136-
assertEquals("/foo", helper.getRequestUri(request));
132+
testKeepSemicolonContent("/foo;a=b;c=d", "/foo;a=b;c=d");
133+
testKeepSemicolonContent("/test;jsessionid=1234", "/test");
134+
testKeepSemicolonContent("/test;JSESSIONID=1234", "/test");
135+
testKeepSemicolonContent("/test;jsessionid=1234;a=b", "/test;a=b");
136+
testKeepSemicolonContent("/test;a=b;jsessionid=1234;c=d", "/test;a=b;c=d");
137+
testKeepSemicolonContent("/test;jsessionid=1234/anotherTest", "/test/anotherTest");
138+
testKeepSemicolonContent("/test;jsessionid=;a=b", "/test;a=b");
139+
testKeepSemicolonContent("/somethingLongerThan12;jsessionid=1234", "/somethingLongerThan12");
140+
}
141+
142+
private void testKeepSemicolonContent(String requestUri, String expectedPath) {
143+
request.setRequestURI(requestUri);
144+
assertEquals(expectedPath, helper.getRequestUri(request));
137145
}
138146

139147
@Test

0 commit comments

Comments
 (0)