ruthst00 commented on code in PR #6773:
URL: https://github.com/apache/jmeter/pull/6773#discussion_r4101905762
##########
src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java:
##########
@@ -770,4 +770,126 @@ 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");
}
+
+ /**
+ * Escaped single-quote inside a single-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 testEscapedSingleQuoteInData() {
+ // Shell representation: --data 'tes\'t'
+ // In Java string: the outer single-quotes are literal chars, the \'
is a backslash + single-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(),
+ "Escaped single-quote inside single-quoted data should be
preserved");
+ }
+
+ /**
+ * 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");
+ }
+
+ // -----------------------------------------------------------------------
+ // Direct unit tests for translateCommandline (tokenizer-level coverage)
+ // -----------------------------------------------------------------------
+
+ /** Plain unquoted tokens are split on spaces. */
+ @Test
+ public void testTranslateCommandlineSimpleTokens() {
+ String[] result = BasicCurlParser.translateCommandline("curl -X POST
http://example.com");
+ assertEquals(4, result.length);
Review Comment:
Fixed
##########
src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java:
##########
@@ -770,4 +770,126 @@ 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");
}
+
+ /**
+ * Escaped single-quote inside a single-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 testEscapedSingleQuoteInData() {
+ // Shell representation: --data 'tes\'t'
+ // In Java string: the outer single-quotes are literal chars, the \'
is a backslash + single-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(),
+ "Escaped single-quote inside single-quoted data should be
preserved");
+ }
+
+ /**
+ * 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");
+ }
+
+ // -----------------------------------------------------------------------
+ // Direct unit tests for translateCommandline (tokenizer-level coverage)
+ // -----------------------------------------------------------------------
+
+ /** Plain unquoted tokens are split on spaces. */
+ @Test
+ public void testTranslateCommandlineSimpleTokens() {
+ String[] result = BasicCurlParser.translateCommandline("curl -X POST
http://example.com");
+ assertEquals(4, result.length);
+ assertEquals("curl", result[0]);
+ assertEquals("-X", result[1]);
+ assertEquals("POST", result[2]);
+ assertEquals("http://example.com", result[3]);
+ }
+
+ /** Single-quoted token: quotes are stripped, content preserved verbatim.
*/
+ @Test
+ public void testTranslateCommandlineSingleQuotedToken() {
+ String[] result = BasicCurlParser.translateCommandline("curl 'hello
world'");
+ assertEquals(2, result.length);
+ assertEquals("curl", result[0]);
+ assertEquals("hello world", result[1]);
+ }
+
+ /** Double-quoted token: quotes are stripped, content preserved verbatim.
*/
+ @Test
+ public void testTranslateCommandlineDoubleQuotedToken() {
+ String[] result = BasicCurlParser.translateCommandline("curl \"hello
world\"");
+ assertEquals(2, result.length);
+ assertEquals("curl", result[0]);
+ assertEquals("hello world", result[1]);
+ }
+
+ /**
+ * Backslash-escaped single-quote inside a single-quoted token must be
+ * treated as a literal single-quote (fix for issue #6374).
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]