Skip to content
Open
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 @@ -58,6 +58,9 @@ public String lookup(final String key) {
final String enc = StandardCharsets.UTF_8.name();
try {
return decode(key, enc);
} catch (final IllegalArgumentException e) {
// Malformed input such as an incomplete "%" escape; squelch and return null like the other lookups.
return null;
} catch (final UnsupportedEncodingException e) {
// Can't happen since UTF-8 is required by the Java specification.
throw IllegalArgumentExceptions.format(e, "%s: source=%s, encoding=%s", e, key, enc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void testExclamation() {
assertEquals(DATA, UrlDecoderStringLookup.INSTANCE.apply("Hello%20World!"));
}

@Test
void testMalformedEscapeReturnsNull() {
assertNull(UrlDecoderStringLookup.INSTANCE.apply("%"));
assertNull(UrlDecoderStringLookup.INSTANCE.apply("%E0%"));
}

@Test
void testNull() {
assertNull(UrlDecoderStringLookup.INSTANCE.apply(null));
Expand Down