Compare encoded params in AbstractFlashMapManager

AbstractFlashMapManager no longer decodes the target query parameters
it needs to use to match to the request after the redirect.

Instead it stores query parameters as-is adn then relies on parsing the
encoded query string after the redirect.

Issue: SPR-12569
This commit is contained in:
Rossen Stoyanchev
2015-03-19 16:57:26 -04:00
parent 46537a76ed
commit de9c9febc3
3 changed files with 68 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -16,11 +16,11 @@
package org.springframework.web.servlet.support;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -30,12 +30,13 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
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;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UrlPathHelper;
/**
* A base class for {@link FlashMapManager} implementations.
*
@@ -172,10 +173,16 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
return false;
}
}
MultiValueMap<String, String> targetParams = flashMap.getTargetRequestParams();
for (String expectedName : targetParams.keySet()) {
for (String expectedValue : targetParams.get(expectedName)) {
if (!ObjectUtils.containsElement(request.getParameterValues(expectedName), expectedValue)) {
UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(request).build();
MultiValueMap<String, String> actualParams = uriComponents.getQueryParams();
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
if (!actualValues.contains(expectedValue)) {
return false;
}
}
@@ -191,7 +198,6 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
flashMap.setTargetRequestPath(path);
decodeParameters(flashMap.getTargetRequestParams(), request);
if (logger.isDebugEnabled()) {
logger.debug("Saving FlashMap=" + flashMap);
@@ -227,17 +233,6 @@ 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))) {
name = getUrlPathHelper().decodeRequestString(request, name);
value = getUrlPathHelper().decodeRequestString(request, value);
params.add(name, value);
}
}
}
/**
* Retrieve saved FlashMap instances from the underlying storage.
* @param request the current request