This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new c8fe1415 Return null for malformed input in UrlDecoderStringLookup 
(#749)
c8fe1415 is described below

commit c8fe141580286aebd42f6eaa90bf4b724dc540eb
Author: Javid Khan <[email protected]>
AuthorDate: Sat Jul 18 22:32:58 2026 +0530

    Return null for malformed input in UrlDecoderStringLookup (#749)
---
 .../java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java | 3 +++
 .../org/apache/commons/text/lookup/UrlDecoderStringLookupTest.java  | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git 
a/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java 
b/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
index 0aabf06b..807a07ce 100644
--- a/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
@@ -58,6 +58,9 @@ final class UrlDecoderStringLookup extends 
AbstractStringLookup {
         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);
diff --git 
a/src/test/java/org/apache/commons/text/lookup/UrlDecoderStringLookupTest.java 
b/src/test/java/org/apache/commons/text/lookup/UrlDecoderStringLookupTest.java
index a6b218b8..a53366ca 100644
--- 
a/src/test/java/org/apache/commons/text/lookup/UrlDecoderStringLookupTest.java
+++ 
b/src/test/java/org/apache/commons/text/lookup/UrlDecoderStringLookupTest.java
@@ -54,6 +54,12 @@ class UrlDecoderStringLookupTest {
         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));

Reply via email to