Browse Source

Sanitize duplicate slashes in request path

This commit removes duplicate slashes in the resolved lookup path when
calling `UrlPathHelper.getLookupPathForRequest`. This is especially
necessary when the path is cleaned from semicolon content and leaves
duplicate slashes in the request path.

Issue: SPR-13455
pull/884/head
Brian Clozel 11 years ago
parent
commit
758ae98af2
  1. 1
      spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java
  2. 15
      spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java

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

@ -421,6 +421,7 @@ public class UrlPathHelper { @@ -421,6 +421,7 @@ public class UrlPathHelper {
private String decodeAndCleanUriString(HttpServletRequest request, String uri) {
uri = removeSemicolonContent(uri);
uri = decodeRequestString(request, uri);
uri = getSanitizedPath(uri);
return uri;
}

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

@ -121,6 +121,13 @@ public class UrlPathHelperTests { @@ -121,6 +121,13 @@ public class UrlPathHelperTests {
request.setRequestURI("/foo;f=F;o=O;o=O/bar;b=B;a=A;r=R");
assertEquals("/foo/bar", helper.getRequestUri(request));
// SPR-13455
request.setServletPath("/foo/1");
request.setRequestURI("/foo/;test/1");
assertEquals("/foo/1", helper.getRequestUri(request));
}
@Test
@ -204,20 +211,20 @@ public class UrlPathHelperTests { @@ -204,20 +211,20 @@ public class UrlPathHelperTests {
assertEquals("/foo/", helper.getLookupPathForRequest(request));
}
//SPR-12372
//SPR-12372 & SPR-13455
@Test
public void defaultServletEndingWithDoubleSlash() throws Exception {
public void removeDuplicateSlashesInPath() throws Exception {
request.setContextPath("/SPR-12372");
request.setPathInfo(null);
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo//bar/");
assertEquals("/foo//bar/", helper.getLookupPathForRequest(request));
assertEquals("/foo/bar/", helper.getLookupPathForRequest(request));
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo/bar//");
assertEquals("/foo/bar//", helper.getLookupPathForRequest(request));
assertEquals("/foo/bar/", helper.getLookupPathForRequest(request));
// "normal" case
request.setServletPath("/foo/bar//");

Loading…
Cancel
Save