Skip to content

Commit

Permalink
Merge pull request #1422 from svorcmar/SPR-15505
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed May 19, 2017
2 parents 44c31a6 + 48a5938 commit 34f1712
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Expand Up @@ -33,7 +33,6 @@
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;


Expand Down Expand Up @@ -173,8 +172,7 @@ protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest req
return false;
}
}
UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(request).build();
MultiValueMap<String, String> actualParams = uriComponents.getQueryParams();
MultiValueMap<String, String> actualParams = getOriginatingRequestParams(request);
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
Expand All @@ -190,6 +188,11 @@ protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest req
return true;
}

private MultiValueMap<String, String> getOriginatingRequestParams(HttpServletRequest request) {
String query = getUrlPathHelper().getOriginatingQueryString(request);
return ServletUriComponentsBuilder.fromPath("/").query(query).build().getQueryParams();
}

@Override
public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) {
if (CollectionUtils.isEmpty(flashMap)) {
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -318,6 +319,25 @@ public void flashAttributesWithQueryParamsWithSpace() throws Exception {
assertEquals("value", flashMap.get("key"));
}

@Test // SPR-15505
public void retrieveAndUpdateMatchByOriginatingPathAndQueryString() {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.setTargetRequestPath("/accounts");
flashMap.addTargetRequestParam("a", "b");

this.flashMapManager.setFlashMaps(Collections.singletonList(flashMap));

this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts");
this.request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "a=b");
this.request.setRequestURI("/mvc/accounts");
this.request.setQueryString("x=y");
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

assertEquals(flashMap, inputFlashMap);
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
}


private static class TestFlashMapManager extends AbstractFlashMapManager {

Expand Down

0 comments on commit 34f1712

Please sign in to comment.