Don't decode URI for content negotiation by extension
Minor bug fix in the ContentNegotiatingViewResolver where decoding the URI prevented proper detection of the file extension in a URL. Issue: SPR-9390
This commit is contained in:
@@ -117,6 +117,9 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
|||||||
|
|
||||||
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
urlPathHelper.setUrlDecode(false);
|
||||||
|
}
|
||||||
|
|
||||||
private int order = Ordered.HIGHEST_PRECEDENCE;
|
private int order = Ordered.HIGHEST_PRECEDENCE;
|
||||||
|
|
||||||
@@ -270,7 +273,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
|||||||
String name = viewResolvers.get(i).getClass().getName() + i;
|
String name = viewResolvers.get(i).getClass().getName() + i;
|
||||||
getApplicationContext().getAutowireCapableBeanFactory().initializeBean(viewResolvers.get(i), name);
|
getApplicationContext().getAutowireCapableBeanFactory().initializeBean(viewResolvers.get(i), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (this.viewResolvers.isEmpty()) {
|
if (this.viewResolvers.isEmpty()) {
|
||||||
logger.warn("Did not find any ViewResolvers to delegate to; please configure them using the " +
|
logger.warn("Did not find any ViewResolvers to delegate to; please configure them using the " +
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPR-8678
|
// SPR-8678
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMediaTypeFilenameWithContextPath() {
|
public void getMediaTypeFilenameWithContextPath() {
|
||||||
request.setContextPath("/project-1.0.0.M3");
|
request.setContextPath("/project-1.0.0.M3");
|
||||||
@@ -110,6 +110,15 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
assertTrue("Context path should be excluded", viewResolver.getMediaTypes(request).isEmpty());
|
assertTrue("Context path should be excluded", viewResolver.getMediaTypes(request).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPR-9390
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMediaTypeFilenameWithEncodedURI() {
|
||||||
|
request.setRequestURI("/quo%20vadis%3f.html");
|
||||||
|
List<MediaType> result = viewResolver.getMediaTypes(request);
|
||||||
|
assertEquals("Invalid content type", Collections.singletonList(new MediaType("text", "html")), result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMediaTypeParameter() {
|
public void getMediaTypeParameter() {
|
||||||
viewResolver.setFavorParameter(true);
|
viewResolver.setFavorParameter(true);
|
||||||
@@ -426,7 +435,7 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
|
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
|
||||||
webAppContext.setServletContext(new MockServletContext());
|
webAppContext.setServletContext(new MockServletContext());
|
||||||
webAppContext.refresh();
|
webAppContext.refresh();
|
||||||
|
|
||||||
UrlBasedViewResolver urlViewResolver = new InternalResourceViewResolver();
|
UrlBasedViewResolver urlViewResolver = new InternalResourceViewResolver();
|
||||||
urlViewResolver.setApplicationContext(webAppContext);
|
urlViewResolver.setApplicationContext(webAppContext);
|
||||||
ViewResolver xmlViewResolver = createMock(ViewResolver.class);
|
ViewResolver xmlViewResolver = createMock(ViewResolver.class);
|
||||||
@@ -435,7 +444,7 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
View xmlView = createMock("application_xml", View.class);
|
View xmlView = createMock("application_xml", View.class);
|
||||||
View jsonView = createMock("application_json", View.class);
|
View jsonView = createMock("application_json", View.class);
|
||||||
viewResolver.setDefaultViews(Arrays.asList(jsonView));
|
viewResolver.setDefaultViews(Arrays.asList(jsonView));
|
||||||
|
|
||||||
String viewName = "redirect:anotherTest";
|
String viewName = "redirect:anotherTest";
|
||||||
Locale locale = Locale.ENGLISH;
|
Locale locale = Locale.ENGLISH;
|
||||||
|
|
||||||
@@ -449,7 +458,7 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
|
|
||||||
verify(xmlViewResolver, xmlView, jsonView);
|
verify(xmlViewResolver, xmlView, jsonView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveViewNoMatch() throws Exception {
|
public void resolveViewNoMatch() throws Exception {
|
||||||
request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");
|
request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");
|
||||||
@@ -505,7 +514,7 @@ public class ContentNegotiatingViewResolverTests {
|
|||||||
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
|
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
|
||||||
webAppContext.setServletContext(new MockServletContext());
|
webAppContext.setServletContext(new MockServletContext());
|
||||||
webAppContext.refresh();
|
webAppContext.refresh();
|
||||||
|
|
||||||
InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
|
InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
|
||||||
nestedResolver.setApplicationContext(webAppContext);
|
nestedResolver.setApplicationContext(webAppContext);
|
||||||
nestedResolver.setViewClass(InternalResourceView.class);
|
nestedResolver.setViewClass(InternalResourceView.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user