Support resource URL encoding at context path
Issue: SPR-13757
This commit is contained in:
parent
beef5ff4c3
commit
dc7ed57c67
|
@ -0,0 +1,26 @@
|
||||||
|
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java
|
||||||
|
index e94a2a6..5b67c58 100644
|
||||||
|
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java
|
||||||
|
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java
|
||||||
|
@@ -89,6 +89,21 @@ public class ResourceUrlEncodingFilterTests {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // SPR-13757
|
||||||
|
+ @Test
|
||||||
|
+ public void encodeURLAtContextPath() throws Exception {
|
||||||
|
+ MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context");
|
||||||
|
+ request.setContextPath("/context");
|
||||||
|
+ request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, this.resourceUrlProvider);
|
||||||
|
+ MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
+
|
||||||
|
+ this.filter.doFilterInternal(request, response, (request1, response1) -> {
|
||||||
|
+ String result = ((HttpServletResponse) response1).encodeURL("/context/resources/bar.css");
|
||||||
|
+ assertEquals("/context/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", result);
|
||||||
|
+ });
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+
|
||||||
|
// SPR-13018
|
||||||
|
@Test
|
||||||
|
public void encodeEmptyURLWithContext() throws Exception {
|
|
@ -95,6 +95,13 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
|
||||||
String requestUri = urlProvider.getPathHelper().getRequestUri(this.request);
|
String requestUri = urlProvider.getPathHelper().getRequestUri(this.request);
|
||||||
String lookupPath = urlProvider.getPathHelper().getLookupPathForRequest(this.request);
|
String lookupPath = urlProvider.getPathHelper().getLookupPathForRequest(this.request);
|
||||||
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
|
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
|
||||||
|
|
||||||
|
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
|
||||||
|
String contextPath = urlProvider.getPathHelper().getContextPath(this.request);
|
||||||
|
if (requestUri.equals(contextPath)) {
|
||||||
|
this.indexLookupPath = requestUri.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,33 @@ public class ResourceUrlEncodingFilterTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPR-13757
|
||||||
|
@Test
|
||||||
|
public void encodeContextPathUrlWithoutSuffix() throws Exception {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context");
|
||||||
|
request.setContextPath("/context");
|
||||||
|
request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, this.resourceUrlProvider);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
this.filter.doFilterInternal(request, response, (request1, response1) -> {
|
||||||
|
String result = ((HttpServletResponse) response1).encodeURL("/context/resources/bar.css");
|
||||||
|
assertEquals("/context/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encodeContextPathUrlWithSuffix() throws Exception {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/");
|
||||||
|
request.setContextPath("/context");
|
||||||
|
request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, this.resourceUrlProvider);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
this.filter.doFilterInternal(request, response, (request1, response1) -> {
|
||||||
|
String result = ((HttpServletResponse) response1).encodeURL("/context/resources/bar.css");
|
||||||
|
assertEquals("/context/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// SPR-13018
|
// SPR-13018
|
||||||
@Test
|
@Test
|
||||||
public void encodeEmptyURLWithContext() throws Exception {
|
public void encodeEmptyURLWithContext() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue