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-07-31 17:30:22 +02:00
parent ce0bce28da
commit af83d2332a
2 changed files with 22 additions and 11 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"));
}
}