diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java index 568b4d9f96..5d1a602d2c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java @@ -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. @@ -157,21 +157,21 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { /** * Whether the given FlashMap matches the current request. - * The default implementation uses the target request path and query - * parameters saved in the FlashMap. + * Uses the expected request path and query parameters saved in the FlashMap. */ protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) { - if (flashMap.getTargetRequestPath() != null) { + String expectedPath = flashMap.getTargetRequestPath(); + if (expectedPath != null) { String requestUri = this.urlPathHelper.getOriginatingRequestUri(request); - if (!requestUri.equals(flashMap.getTargetRequestPath()) - && !requestUri.equals(flashMap.getTargetRequestPath() + "/")) { + if (!requestUri.equals(expectedPath) + && !requestUri.equals(expectedPath + "/")) { return false; } } MultiValueMap targetParams = flashMap.getTargetRequestParams(); - for (String paramName : targetParams.keySet()) { - for (String targetValue : targetParams.get(paramName)) { - if (!ObjectUtils.containsElement(request.getParameterValues(paramName), targetValue)) { + for (String expectedName : targetParams.keySet()) { + for (String expectedValue : targetParams.get(expectedName)) { + if (!ObjectUtils.containsElement(request.getParameterValues(expectedName), expectedValue)) { return false; } } @@ -219,7 +219,9 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { private void decodeParameters(MultiValueMap params, HttpServletRequest request) { for (String name : new ArrayList(params.keySet())) { for (String value : new ArrayList(params.remove(name))) { - params.add(this.urlPathHelper.decodeRequestString(request, name), this.urlPathHelper.decodeRequestString(request, value)); + name = this.urlPathHelper.decodeRequestString(request, name); + value = this.urlPathHelper.decodeRequestString(request, value); + params.add(name, value); } } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java index 94e755d814..5c763eca1c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java @@ -30,6 +30,7 @@ import org.junit.Test; import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletResponse; +import org.springframework.util.MultiValueMap; import org.springframework.web.servlet.FlashMap; import org.springframework.web.util.WebUtils; @@ -261,6 +262,8 @@ public class FlashMapManagerTests { assertEquals("/once/only", flashMap.getTargetRequestPath()); } + // SPR-9657, SPR-11504 + @Test public void saveOutputFlashMapDecodeParameters() throws Exception { this.request.setCharacterEncoding("UTF-8"); @@ -274,10 +277,9 @@ public class FlashMapManagerTests { flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); - assertEquals(Arrays.asList("\u0410\u0410", "\u0411\u0411", "\u0412\u0412"), - flashMap.getTargetRequestParams().get("key")); - assertEquals(Arrays.asList("value"), - flashMap.getTargetRequestParams().get(":/?#[]@")); + MultiValueMap targetRequestParams = flashMap.getTargetRequestParams(); + assertEquals(Arrays.asList("\u0410\u0410", "\u0411\u0411", "\u0412\u0412"), targetRequestParams.get("key")); + assertEquals(Arrays.asList("value"), targetRequestParams.get(":/?#[]@")); }