Fix issue w/ use of UrlPathHelper's urlDecode property
Before this change the getPathWithinServletMapping method of
UrlPathHelper could not work properly when a default servlet mapping
(i.e. "/") was used in combination with urlDecode=false. The fact that
the getServletPath() method of HttpServletRequest always returns a
decoded path was getting in the way.
Although there is no way to check Servlet mappings through the Servlet
API, this change aims to detect the given scenario and returns the full
path following the context path thus avoiding URL decoding.
Note that the same can be achieved by setting urlDecode=false and
alwaysUseFullPath=true. However this change ensures that urlDecode
works properly without having to know that.
Issue: SPR-11101
(cherry picked from commit 12598f8)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,11 +32,12 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class UrlPathHelperTests {
|
||||
|
||||
private static final String WEBSPHERE_URI_ATTRIBUTE = "com.ibm.websphere.servlet.uri_non_decoded";
|
||||
|
||||
private UrlPathHelper helper;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private static final String WEBSPHERE_URI_ATTRIBUTE = "com.ibm.websphere.servlet.uri_non_decoded";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -44,6 +45,7 @@ public class UrlPathHelperTests {
|
||||
request = new MockHttpServletRequest();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getPathWithinApplication() {
|
||||
request.setContextPath("/petclinic");
|
||||
@@ -77,6 +79,17 @@ public class UrlPathHelperTests {
|
||||
assertEquals("Incorrect path returned", "/welcome.html", helper.getPathWithinServletMapping(request));
|
||||
}
|
||||
|
||||
@Test // SPR-11101
|
||||
public void getPathWithinServletWithoutUrlDecoding() {
|
||||
request.setContextPath("/SPR-11101");
|
||||
request.setServletPath("/test_url_decoding/a/b");
|
||||
request.setRequestURI("/test_url_decoding/a%2Fb");
|
||||
|
||||
helper.setUrlDecode(false);
|
||||
String actual = helper.getPathWithinServletMapping(request);
|
||||
assertEquals("/test_url_decoding/a%2Fb", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestUri() {
|
||||
request.setRequestURI("/welcome.html");
|
||||
@@ -141,11 +154,10 @@ public class UrlPathHelperTests {
|
||||
|
||||
|
||||
//
|
||||
// suite of tests root requests for default servlets (SRV 11.2) on Websphere vs Tomcat and other containers
|
||||
// see: http://jira.springframework.org/browse/SPR-7064
|
||||
// Suite of tests root requests for default servlets (SRV 11.2) on WebSphere vs Tomcat and other containers
|
||||
// See: http://jira.springframework.org/browse/SPR-7064
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// / mapping (default servlet)
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user