Skip to content

Commit 2acc5db

Browse files
thcedCopilot
andauthored
fix: Catch URLDecoder exceptions
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 04d4b68 commit 2acc5db

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/com/retailsvc/http/internal/FormUrlEncodedParser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ public Map<String, Object> parse(byte[] body, String contentTypeHeader) {
3131
int eq = pair.indexOf('=');
3232
String rawKey = eq < 0 ? pair : pair.substring(0, eq);
3333
String rawValue = eq < 0 ? "" : pair.substring(eq + 1);
34-
String key = URLDecoder.decode(rawKey, charset);
35-
String value = URLDecoder.decode(rawValue, charset);
34+
String key = decodeComponent(rawKey, charset);
35+
String value = decodeComponent(rawValue, charset);
3636
addEntry(out, key, value);
3737
}
3838
return out;
3939
}
4040

41+
private static String decodeComponent(String value, Charset charset) {
42+
try {
43+
return URLDecoder.decode(value, charset);
44+
} catch (IllegalArgumentException ex) {
45+
throw new ValidationException("/body", "decode", "Malformed form URL encoding", ex);
46+
}
47+
}
48+
4149
private static void addEntry(Map<String, Object> out, String key, String value) {
4250
Object existing = out.get(key);
4351
if (existing == null) {

0 commit comments

Comments
 (0)