From e6920a59fade8ea74710bf806ec8ae6e40999b1e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 1 Nov 2011 15:19:04 +0000 Subject: [PATCH] SPR-8779 Use original URI in FlashMap match logic to account for URL rewriting. --- .../support/DefaultFlashMapManager.java | 2 +- .../support/DefaultFlashMapManagerTests.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java index ad3ab94587..3585279b2b 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.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; diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java index d644b50593..936670602f 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.java @@ -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. @@ -83,6 +84,25 @@ public class DefaultFlashMapManagerTests { assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); 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 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() {