Fix regression in HttpPutFormContentFilter

Re-arrange the checks so that if there is no form parameter, then
immediately and unconditionally delegate to super.getParameterValues().
Or reversely if there is no super.getParameterValues() then return the
form parameter.

So the only remaining case is when combining values present in both.
In that case we'll take both only if a queryString exists.

One extra fix is to not even wrap the request if we did not parse any
form parameters at all which can happen with HttpHiddenMethodFilter.

Issue: SPR-15828, 15835
This commit is contained in:
Rossen Stoyanchev
2017-08-01 12:41:45 +02:00
parent 5f07434360
commit 35248498ae
2 changed files with 23 additions and 12 deletions

View File

@@ -58,7 +58,7 @@ public class HttpPutFormContentFilterTests {
@Test
public void wrapPutAndPatchOnly() throws Exception {
request.setContent("".getBytes("ISO-8859-1"));
request.setContent("foo=bar".getBytes("ISO-8859-1"));
for (HttpMethod method : HttpMethod.values()) {
request.setMethod(method.name());
filterChain = new MockFilterChain();
@@ -204,4 +204,13 @@ public class HttpPutFormContentFilterTests {
assertArrayEquals(new String[] {"value4"}, parameters.get("name4"));
}
@Test // SPR-15835
public void hiddenHttpMethodFilterFollowedByHttpPutFormContentFilter() throws Exception {
request.addParameter("_method", "PUT");
request.addParameter("hiddenField", "testHidden");
filter.doFilter(request, response, filterChain);
assertArrayEquals(new String[]{"testHidden"}, filterChain.getRequest().getParameterValues("hiddenField"));
}
}