Merge branch '5.2.x' into master
This commit is contained in:
@@ -608,7 +608,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) {
|
||||
@@ -622,6 +623,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
|
||||
@@ -726,7 +743,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);
|
||||
|
||||
@@ -126,7 +126,7 @@ public class UrlPathHelperTests {
|
||||
assertThat(helper.getRequestUri(request)).isEqualTo("/foo;a=b;c=d");
|
||||
|
||||
request.setRequestURI("/foo;jsessionid=c0o7fszeb1");
|
||||
assertThat(helper.getRequestUri(request)).isEqualTo("/foo;jsessionid=c0o7fszeb1");
|
||||
assertThat(helper.getRequestUri(request)).isEqualTo("/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -389,6 +389,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
assertContentDisposition(processor, true, "/hello.json;a=b;setup.dataless", "unknown ext in path params");
|
||||
assertContentDisposition(processor, true, "/hello.dataless;a=b;setup.json", "unknown ext in filename");
|
||||
assertContentDisposition(processor, false, "/hello.json;a=b;setup.json", "safe extensions");
|
||||
assertContentDisposition(processor, true, "/hello.json;jsessionid=foo.bar", "jsessionid shouldn't cause issue");
|
||||
|
||||
// encoded dot
|
||||
assertContentDisposition(processor, true, "/hello%2Edataless;a=b;setup.json", "encoded dot in filename");
|
||||
|
||||
@@ -72,6 +72,30 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
assertThat(response.getContentAsString()).isEqualTo("test-42-7");
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest // gh-25864
|
||||
void literalMappingWithPathParams(boolean usePathPatterns) throws Exception {
|
||||
initDispatcherServlet(MultipleUriTemplateController.class, usePathPatterns);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/data");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(response.getContentAsString()).isEqualTo("test");
|
||||
|
||||
if (!usePathPatterns) {
|
||||
request = new MockHttpServletRequest("GET", "/data;foo=bar");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/data;jsessionid=123");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(response.getContentAsString()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest
|
||||
void multiple(boolean usePathPatterns) throws Exception {
|
||||
initDispatcherServlet(MultipleUriTemplateController.class, usePathPatterns);
|
||||
@@ -379,6 +403,10 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther);
|
||||
}
|
||||
|
||||
@RequestMapping("/data")
|
||||
void handleWithLiteralMapping(Writer writer) throws IOException {
|
||||
writer.write("test");
|
||||
}
|
||||
}
|
||||
|
||||
@Controller
|
||||
|
||||
Reference in New Issue
Block a user