Refine FormHttpMessageConverter exception handling

FormHttpMessageConverter could throw a more specific
HttpMessageNotReadableException instead of an IllegalArgumentException
when the http form data is invalid.

See gh-34594
Signed-off-by: Russell Bolles <rbolles@netflix.com>
This commit is contained in:
Russell Bolles
2025-03-13 12:22:25 -07:00
committed by Sébastien Deleuze
parent 6c231804a0
commit 573e74b8bd
2 changed files with 47 additions and 4 deletions

View File

@@ -353,12 +353,22 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
for (String pair : pairs) {
int idx = pair.indexOf('=');
if (idx == -1) {
result.add(URLDecoder.decode(pair, charset), null);
try {
result.add(URLDecoder.decode(pair, charset), null);
}
catch (IllegalArgumentException ex) {
throw new HttpMessageNotReadableException("Could not decode HTTP form payload", ex, inputMessage);
}
}
else {
String name = URLDecoder.decode(pair.substring(0, idx), charset);
String value = URLDecoder.decode(pair.substring(idx + 1), charset);
result.add(name, value);
try {
String name = URLDecoder.decode(pair.substring(0, idx), charset);
String value = URLDecoder.decode(pair.substring(idx + 1), charset);
result.add(name, value);
}
catch (IllegalArgumentException ex) {
throw new HttpMessageNotReadableException("Could not decode HTTP form payload", ex, inputMessage);
}
}
}
return result;