From 8337f4bf2045d09d17c54617e91b5dbc0593c73e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 1 Nov 2011 16:26:25 +0000 Subject: [PATCH] SPR-8789 Support request with multiple param values in FlahMap matching logic --- .../resources/changelog.txt | 3 +- .../support/DefaultFlashMapManager.java | 9 ++--- .../support/DefaultFlashMapManagerTests.java | 36 ++++++++++++++++--- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/build-spring-framework/resources/changelog.txt b/build-spring-framework/resources/changelog.txt index 4a4ae1165ee..ffb489777cc 100644 --- a/build-spring-framework/resources/changelog.txt +++ b/build-spring-framework/resources/changelog.txt @@ -15,7 +15,8 @@ Changes in version 3.1 RC2 (2011-11-15) * fixed MethodInvokingJobDetailFactoryBean's Quartz 2.0 support * RmiClientInterceptor detects nested SocketException as connect failure as well * fixed StandardServlet/PortletEnvironment to check for JNDI (for Google App Engine compatibility) - +* Use original request URI in FlashMap matching logic to account for URL rewriting +* Support target request with multiple parameter values in FlahMap matching logic Changes in version 3.1 RC1 (2011-10-11) --------------------------------------- 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 3585279b2b1..c10bb36f04d 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 @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.FlashMap; import org.springframework.web.servlet.FlashMapManager; @@ -123,10 +124,10 @@ public class DefaultFlashMapManager implements FlashMapManager { return false; } } - MultiValueMap params = flashMap.getTargetRequestParams(); - for (String key : params.keySet()) { - for (String value : params.get(key)) { - if (!value.equals(request.getParameter(key))) { + MultiValueMap targetParams = flashMap.getTargetRequestParams(); + for (String paramName : targetParams.keySet()) { + for (String targetValue : targetParams.get(paramName)) { + if (!ObjectUtils.containsElement(request.getParameterValues(paramName), targetValue)) { 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 936670602f0..61aaa808e6c 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 @@ -133,22 +133,48 @@ public class DefaultFlashMapManagerTests { this.flashMapManager.requestStarted(this.request); assertNull(RequestContextUtils.getInputFlashMap(this.request)); - assertEquals("FlashMap should have been removed", 1, getFlashMaps().size()); + assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); - clearRequestAttributes(); + clearFlashMapRequestAttributes(); this.request.setParameter("number", "two"); this.flashMapManager.requestStarted(this.request); assertNull(RequestContextUtils.getInputFlashMap(this.request)); - assertEquals("FlashMap should have been removed", 1, getFlashMaps().size()); + assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); - clearRequestAttributes(); + clearFlashMapRequestAttributes(); this.request.setParameter("number", "one"); this.flashMapManager.requestStarted(this.request); assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); } + + // SPR-8798 + + @Test + public void lookupFlashMapWithMultiValueParam() { + FlashMap flashMap = new FlashMap(); + flashMap.put("name", "value"); + flashMap.addTargetRequestParam("id", "1"); + flashMap.addTargetRequestParam("id", "2"); + + List allMaps = createFlashMaps(); + allMaps.add(flashMap); + + this.request.setParameter("id", "1"); + this.flashMapManager.requestStarted(this.request); + + assertNull(RequestContextUtils.getInputFlashMap(this.request)); + assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); + + clearFlashMapRequestAttributes(); + this.request.addParameter("id", "2"); + this.flashMapManager.requestStarted(this.request); + + assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); + assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); + } @Test public void lookupFlashMapSortOrder() { @@ -284,7 +310,7 @@ public class DefaultFlashMapManagerTests { return allMaps; } - private void clearRequestAttributes() { + private void clearFlashMapRequestAttributes() { request.removeAttribute(INPUT_FLASH_MAP_ATTRIBUTE); request.removeAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE); }