ruthst00 commented on code in PR #6773:
URL: https://github.com/apache/jmeter/pull/6773#discussion_r4106126264
##########
src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java:
##########
@@ -770,4 +770,153 @@ public void testIsValidCookie() {
assertTrue(BasicCurlParser.isValidCookie("a=b;c=d"), "The string
should be cookies");
assertFalse(BasicCurlParser.isValidCookie("test.txt"), "A filename is
not a valid cookie");
}
+
+ /**
+ * A single quote inside a value can be written using the POSIX idiom
+ * {@code 'tes'\''t'}: close the single-quoted region, escape the single
+ * quote with a backslash outside quotes, then reopen single-quoting.
+ */
+ @Test
+ public void testEscapedSingleQuoteInData() {
+ // Shell representation: --data 'tes'\''t'
+ // In Java string: 'tes'\'t' (close quote, backslash+quote outside,
reopen quote)
+ String curl = " curl -X POST \"localhost.com\" --data 'tes'\\''t'";
+ BasicCurlParser basicCurlParser = new BasicCurlParser();
+ BasicCurlParser.Request request = basicCurlParser.parse(curl);
+ assertEquals("tes't", request.getPostData(),
+ "POSIX single-quote idiom 'tes'\\''t' should produce tes't");
+ }
+
+ /**
+ * Escaped double-quote inside a double-quoted --data value must not cause
+ * "unbalanced quotes" and must be included literally in the post data.
+ * Reproduces https://github.com/apache/jmeter/issues/6374
+ */
+ @Test
+ public void testEscapedDoubleQuoteInData() {
+ // Shell representation: --data "tes\"t"
+ String curl = " curl -X POST \"localhost.com\" --data \"tes\\\"t\"";
+ BasicCurlParser basicCurlParser = new BasicCurlParser();
+ BasicCurlParser.Request request = basicCurlParser.parse(curl);
+ assertEquals("tes\"t", request.getPostData(),
+ "Escaped double-quote inside double-quoted data should be
preserved");
+ }
+
+ static
java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments>
translateCommandlineCases() {
+ return java.util.stream.Stream.of(
+ // Plain unquoted tokens split on spaces
+ // bash: printf "%s\n" curl -X POST http://example.com
+ // → curl / -X / POST / http://example.com
+ org.junit.jupiter.params.provider.Arguments.of(
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]