Reinstate removal of jsessionid from lookup path

Closes gh-25864
This commit is contained in:
Rossen Stoyanchev
2020-10-07 11:31:52 +01:00
parent 94d330695f
commit 1c120f05eb
4 changed files with 58 additions and 8 deletions

View File

@@ -521,7 +521,8 @@ public class UrlPathHelper {
* @return the updated URI string
*/
public String removeSemicolonContent(String requestUri) {
return (this.removeSemicolonContent ? removeSemicolonContentInternal(requestUri) : requestUri);
return (this.removeSemicolonContent ?
removeSemicolonContentInternal(requestUri) : removeJsessionid(requestUri));
}
private String removeSemicolonContentInternal(String requestUri) {
@@ -535,6 +536,22 @@ public class UrlPathHelper {
return requestUri;
}
private String removeJsessionid(String requestUri) {
String key = ";jsessionid=";
int index = requestUri.toLowerCase().indexOf(key);
if (index == -1) {
return requestUri;
}
String start = requestUri.substring(0, index);
for (int i = key.length(); i < requestUri.length(); i++) {
char c = requestUri.charAt(i);
if (c == ';' || c == '/') {
return start + requestUri.substring(i);
}
}
return start;
}
/**
* Decode the given URI path variables via {@link #decodeRequestString} unless
* {@link #setUrlDecode} is set to {@code true} in which case it is assumed
@@ -639,7 +656,13 @@ public class UrlPathHelper {
* <li>{@code defaultEncoding=}{@link WebUtils#DEFAULT_CHARACTER_ENCODING}
* </ul>
*/
public static final UrlPathHelper rawPathInstance = new UrlPathHelper();
public static final UrlPathHelper rawPathInstance = new UrlPathHelper() {
@Override
public String removeSemicolonContent(String requestUri) {
return requestUri;
}
};
static {
rawPathInstance.setAlwaysUseFullPath(true);

View File

@@ -133,7 +133,7 @@ public class UrlPathHelperTests {
assertEquals("/foo;a=b;c=d", helper.getRequestUri(request));
request.setRequestURI("/foo;jsessionid=c0o7fszeb1");
assertEquals("/foo;jsessionid=c0o7fszeb1", helper.getRequestUri(request));
assertEquals("/foo", helper.getRequestUri(request));
}
@Test