提交 8337f4bf 编写于 作者: R Rossen Stoyanchev

SPR-8789 Support request with multiple param values in FlahMap matching logic

上级 e6920a59
......@@ -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)
---------------------------------------
......
......@@ -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<String, String> params = flashMap.getTargetRequestParams();
for (String key : params.keySet()) {
for (String value : params.get(key)) {
if (!value.equals(request.getParameter(key))) {
MultiValueMap<String, String> targetParams = flashMap.getTargetRequestParams();
for (String paramName : targetParams.keySet()) {
for (String targetValue : targetParams.get(paramName)) {
if (!ObjectUtils.containsElement(request.getParameterValues(paramName), targetValue)) {
return false;
}
}
......
......@@ -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<FlashMap> 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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册