Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private static byte[] fromHex(final String text) {
final var c = text.charAt(i++);
if (c == '%') {
if (i > text.length() - 2) {
break; // unterminated sequence
// A '%' that is not followed by two hex digits is a truncated escape sequence.
throw new IllegalArgumentException();
}
final var c1 = text.charAt(i++);
final var c2 = text.charAt(i++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ void testDecodeInvalidPercentEncoded() throws Exception {
assertThrows(IllegalArgumentException.class, () -> RFC2231Utils.decodeText("ISO-8859-1''hello%3\u8a35"));
}

@Test
void testDecodeTruncatedPercentEncoded() throws Exception {
assertThrows(IllegalArgumentException.class, () -> RFC2231Utils.decodeText("ISO-8859-1''hello%"));
assertThrows(IllegalArgumentException.class, () -> RFC2231Utils.decodeText("ISO-8859-1''hello%3"));
}

@Test
void testDecodeIso88591() throws Exception {
assertEncoded("\u00A3 rate", "iso-8859-1'en'%A3%20rate"); // "£ rate"
Expand Down
Loading