SPR-8779 Use original URI in FlashMap match logic to account for URL rewriting.

master
Rossen Stoyanchev 13 years ago
parent 1164f5a9fc
commit e6920a59fa
  1. 2
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java
  2. 20
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java

@ -117,7 +117,7 @@ public class DefaultFlashMapManager implements FlashMapManager {
*/
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
if (flashMap.getTargetRequestPath() != null) {
String requestUri = this.urlPathHelper.getRequestUri(request);
String requestUri = this.urlPathHelper.getOriginatingRequestUri(request);
if (!requestUri.equals(flashMap.getTargetRequestPath())
&& !requestUri.equals(flashMap.getTargetRequestPath() + "/")) {
return false;

@ -33,6 +33,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.servlet.FlashMap;
import org.springframework.web.util.WebUtils;
/**
* Test fixture for {@link DefaultFlashMapManager} tests.
@ -84,6 +85,25 @@ public class DefaultFlashMapManagerTests {
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size());
}
// SPR-8779
@Test
public void lookupFlashMapByOriginatingPath() {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.setTargetRequestPath("/accounts");
List<FlashMap> allMaps = createFlashMaps();
allMaps.add(flashMap);
this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts");
this.request.setRequestURI("/mvc/accounts");
this.flashMapManager.requestStarted(this.request);
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request));
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size());
}
@Test
public void lookupFlashMapByPathWithTrailingSlash() {
FlashMap flashMap = new FlashMap();

Loading…
Cancel
Save