Skip to content

Commit

Permalink
Reject null form data names
Browse files Browse the repository at this point in the history
...or skip if there are no values either.

Closes gh-22372
  • Loading branch information
rstoyanchev committed Nov 13, 2019
1 parent f2b9264 commit 2c1afca
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -40,6 +40,7 @@
import org.springframework.http.StreamingHttpOutputMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.MultiValueMap;
Expand Down Expand Up @@ -415,7 +416,11 @@ else if (mediaType.getCharset() == null) {

protected String serializeForm(MultiValueMap<String, Object> formData, Charset charset) {
StringBuilder builder = new StringBuilder();
formData.forEach((name, values) ->
formData.forEach((name, values) -> {
if (name == null) {
Assert.isTrue(CollectionUtils.isEmpty(values), "Null name in form data: " + formData);
return;
}
values.forEach(value -> {
try {
if (builder.length() != 0) {
Expand All @@ -430,7 +435,8 @@ protected String serializeForm(MultiValueMap<String, Object> formData, Charset c
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);
}
}));
});
});

return builder.toString();
}
Expand Down

0 comments on commit 2c1afca

Please sign in to comment.