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

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 2562f0c639 Fix Bug 6456: Handle malformed percent-encoded URLs 
gracefully
2562f0c639 is described below

commit 2562f0c6394d1880144a4f9ab5a3e471209f85ca
Author: Claude <[email protected]>
AuthorDate: Tue Nov 11 18:31:18 2025 +0000

    Fix Bug 6456: Handle malformed percent-encoded URLs gracefully
    
    When recording HTTP traffic via the HTTP(S) Test Script Recorder, JMeter
    would crash with IllegalArgumentException when encountering malformed
    percent-encoded parameters (e.g., "%u2", "%ZZ", "text%") from real-world
    web applications.
    
    Changes:
    - HTTPArgument constructor now catches IllegalArgumentException from
      URLDecoder.decode() in addition to UnsupportedEncodingException
    - When malformed encoding is detected, the original encoded value is
      preserved and a warning is logged instead of crashing
    - Added comprehensive test cases covering various malformed encoding
      scenarios: incomplete hex sequences, invalid hex characters, truncated
      percent signs, and mixed valid/invalid encoding
    
    This allows JMeter to successfully record and test applications with
    encoding bugs, which is a legitimate use case for a testing tool.
---
 .../jmeter/protocol/http/util/HTTPArgument.java    |  7 +++++
 .../protocol/http/util/TestHTTPArgument.java       | 33 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git 
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java
 
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java
index be534a3b23..9fc3a2be5b 100644
--- 
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java
+++ 
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java
@@ -161,6 +161,13 @@ public class HTTPArgument extends Argument implements 
Serializable {
             } catch (UnsupportedEncodingException e) {
                 log.error("{} encoding not supported!", contentEncoding);
                 throw new Error(e.toString(), e);
+            } catch (IllegalArgumentException e) {
+                // Handle malformed percent-encoded strings (e.g., "%u2", 
"%ZZ", "text%")
+                // This can occur when recording real-world web traffic with 
encoding bugs
+                // See Bug 6456
+                log.warn("Malformed percent-encoded parameter detected - using 
original value. " +
+                        "Name: '{}', Value: '{}', Error: {}", name, value, 
e.getMessage());
+                // Keep the original encoded values as-is
             }
         }
         setName(name);
diff --git 
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
 
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
index 1c944e8f8d..7a999cf739 100644
--- 
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
+++ 
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
@@ -93,4 +93,37 @@ public class TestHTTPArgument {
         assertEquals("", arg.getEncodedName());
         assertEquals("\00\01\07", arg.getEncodedValue());
     }
+
+    @Test
+    public void testMalformedPercentEncoding() throws Exception {
+        // Test case for Bug 6456: Handle malformed percent-encoded strings 
gracefully
+        // These are real-world cases that can occur when recording web 
application traffic
+
+        // Case 1: Incomplete hex sequence "%u2" - reported in the issue
+        HTTPArgument arg1 = new HTTPArgument("param", "value%u2", true);
+        // Should preserve the original malformed value instead of throwing 
IllegalArgumentException
+        assertEquals("param", arg1.getName());
+        assertEquals("value%u2", arg1.getValue());
+
+        // Case 2: Invalid hex character in encoding
+        HTTPArgument arg2 = new HTTPArgument("name", "test%ZZ", true);
+        assertEquals("name", arg2.getName());
+        assertEquals("test%ZZ", arg2.getValue());
+
+        // Case 3: Truncated percent at end of string
+        HTTPArgument arg3 = new HTTPArgument("data", "some%", true);
+        assertEquals("data", arg3.getName());
+        assertEquals("some%", arg3.getValue());
+
+        // Case 4: Percent followed by single hex digit
+        HTTPArgument arg4 = new HTTPArgument("field", "text%2", true);
+        assertEquals("field", arg4.getName());
+        assertEquals("text%2", arg4.getValue());
+
+        // Case 5: Mix of valid and invalid encoding
+        HTTPArgument arg5 = new HTTPArgument("mixed", "hello%20world%u2", 
true);
+        assertEquals("mixed", arg5.getName());
+        // Valid %20 should decode to space, but %u2 is malformed
+        assertEquals("hello%20world%u2", arg5.getValue());
+    }
 }

Reply via email to