Browse Source

SPR-8596 Detect case in UriPathHelper where originating request query (before forwarding) is null.

pull/7/head
Rossen Stoyanchev 13 years ago
parent
commit
7bf44f06a0
  1. 11
      org.springframework.web/src/main/java/org/springframework/web/util/UrlPathHelper.java
  2. 22
      org.springframework.web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java

11
org.springframework.web/src/main/java/org/springframework/web/util/UrlPathHelper.java

@ -287,14 +287,15 @@ public class UrlPathHelper { @@ -287,14 +287,15 @@ public class UrlPathHelper {
* @return the query string
*/
public String getOriginatingQueryString(HttpServletRequest request) {
String queryString = (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
if (queryString == null) {
queryString = request.getQueryString();
if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null) ||
(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
}
else {
return request.getQueryString();
}
return queryString;
}
/**
* Decode the supplied URI string and strips any extraneous portion after a ';'.
*/

22
org.springframework.web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java

@ -289,4 +289,26 @@ public class UrlPathHelperTests { @@ -289,4 +289,26 @@ public class UrlPathHelperTests {
request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo/");
tomcatCasualServletFolder();
}
@Test
public void getOriginatingQueryString() {
request.setQueryString("forward=on");
request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path");
request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "original=on");
assertEquals("original=on", this.helper.getOriginatingQueryString(request));
}
@Test
public void getOriginatingQueryStringNotPresent() {
request.setQueryString("forward=true");
assertEquals("forward=true", this.helper.getOriginatingQueryString(request));
}
@Test
public void getOriginatingQueryStringIsNull() {
request.setQueryString("forward=true");
request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/path");
assertNull(this.helper.getOriginatingQueryString(request));
}
}
Loading…
Cancel
Save