Browse Source

Decode target parameters prior to saving a FlashMap

The target parameters for a FlashMap must be decoded to be able to
match them to the parameters of incoming requests given that the
HttpServletRequest returns decoded request parameters.

Issue: SPR-9657
Backport Issue: SPR-9701
3.1.x
Rossen Stoyanchev 13 years ago
parent
commit
d8166d6155
  1. 16
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java
  2. 16
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/AbstractFlashMapManagerTests.java

16
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java

@ -177,12 +177,18 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { @@ -177,12 +177,18 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
if (CollectionUtils.isEmpty(flashMap)) {
return;
}
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
flashMap.setTargetRequestPath(path);
flashMap.startExpirationPeriod(this.flashMapTimeout);
decodeParameters(flashMap.getTargetRequestParams(), request);
if (logger.isDebugEnabled()) {
logger.debug("Saving FlashMap=" + flashMap);
}
flashMap.startExpirationPeriod(this.flashMapTimeout);
synchronized (writeLock) {
List<FlashMap> allMaps = retrieveFlashMaps(request);
allMaps = (allMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : allMaps;
@ -203,6 +209,14 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { @@ -203,6 +209,14 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
return path;
}
private void decodeParameters(MultiValueMap<String, String> params, HttpServletRequest request) {
for (String name : new ArrayList<String>(params.keySet())) {
for (String value : new ArrayList<String>(params.remove(name))) {
params.add(name, this.urlPathHelper.decodeRequestString(request, value));
}
}
}
/**
* Update the FlashMap instances in some underlying storage.
* @param flashMaps a non-empty list of FlashMap instances to save

16
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/support/AbstractFlashMapManagerTests.java

@ -264,6 +264,22 @@ public class AbstractFlashMapManagerTests { @@ -264,6 +264,22 @@ public class AbstractFlashMapManagerTests {
assertEquals("/once/only", flashMap.getTargetRequestPath());
}
@Test
public void saveOutputFlashMapDecodeParameters() throws Exception {
this.request.setCharacterEncoding("UTF-8");
FlashMap flashMap = new FlashMap();
flashMap.put("anyKey", "anyValue");
flashMap.addTargetRequestParam("key", "%D0%90%D0%90");
flashMap.addTargetRequestParam("key", "%D0%91%D0%91");
flashMap.addTargetRequestParam("key", "%D0%92%D0%92");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertEquals(Arrays.asList("\u0410\u0410", "\u0411\u0411", "\u0412\u0412"),
flashMap.getTargetRequestParams().get("key"));
}
private static class TestFlashMapManager extends AbstractFlashMapManager {

Loading…
Cancel
Save