Skip to content

Commit 2562f0c

Browse files
claudevlsi
authored andcommitted
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.
1 parent 02e5f59 commit 2562f0c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded, String co
161161
} catch (UnsupportedEncodingException e) {
162162
log.error("{} encoding not supported!", contentEncoding);
163163
throw new Error(e.toString(), e);
164+
} catch (IllegalArgumentException e) {
165+
// Handle malformed percent-encoded strings (e.g., "%u2", "%ZZ", "text%")
166+
// This can occur when recording real-world web traffic with encoding bugs
167+
// See Bug 6456
168+
log.warn("Malformed percent-encoded parameter detected - using original value. " +
169+
"Name: '{}', Value: '{}', Error: {}", name, value, e.getMessage());
170+
// Keep the original encoded values as-is
164171
}
165172
}
166173
setName(name);

src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,37 @@ public void testEncoding() throws Exception {
9393
assertEquals("", arg.getEncodedName());
9494
assertEquals("\00\01\07", arg.getEncodedValue());
9595
}
96+
97+
@Test
98+
public void testMalformedPercentEncoding() throws Exception {
99+
// Test case for Bug 6456: Handle malformed percent-encoded strings gracefully
100+
// These are real-world cases that can occur when recording web application traffic
101+
102+
// Case 1: Incomplete hex sequence "%u2" - reported in the issue
103+
HTTPArgument arg1 = new HTTPArgument("param", "value%u2", true);
104+
// Should preserve the original malformed value instead of throwing IllegalArgumentException
105+
assertEquals("param", arg1.getName());
106+
assertEquals("value%u2", arg1.getValue());
107+
108+
// Case 2: Invalid hex character in encoding
109+
HTTPArgument arg2 = new HTTPArgument("name", "test%ZZ", true);
110+
assertEquals("name", arg2.getName());
111+
assertEquals("test%ZZ", arg2.getValue());
112+
113+
// Case 3: Truncated percent at end of string
114+
HTTPArgument arg3 = new HTTPArgument("data", "some%", true);
115+
assertEquals("data", arg3.getName());
116+
assertEquals("some%", arg3.getValue());
117+
118+
// Case 4: Percent followed by single hex digit
119+
HTTPArgument arg4 = new HTTPArgument("field", "text%2", true);
120+
assertEquals("field", arg4.getName());
121+
assertEquals("text%2", arg4.getValue());
122+
123+
// Case 5: Mix of valid and invalid encoding
124+
HTTPArgument arg5 = new HTTPArgument("mixed", "hello%20world%u2", true);
125+
assertEquals("mixed", arg5.getName());
126+
// Valid %20 should decode to space, but %u2 is malformed
127+
assertEquals("hello%20world%u2", arg5.getValue());
128+
}
96129
}

0 commit comments

Comments
 (0)