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

fschumacher 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 9d2ba68  Sending mime type with parameter throws 
IllegalArgumentException
9d2ba68 is described below

commit 9d2ba68c16a079c4e7156d847ed9acb7a6d4bb88
Author: Felix Schumacher <[email protected]>
AuthorDate: Wed Dec 23 17:12:47 2020 +0100

    Sending mime type with parameter throws IllegalArgumentException
    
    More stuff from that bugzilla entry:
    
    * Allow empty headers to be added
    
    Bugzilla Id: 65024
---
 .../apache/jmeter/protocol/http/curl/BasicCurlParser.java  | 14 ++++++++++----
 .../java/org/apache/jmeter/curl/BasicCurlParserTest.java   | 10 ++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git 
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
 
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
index 4fb6581..b1dd350 100644
--- 
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
+++ 
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
@@ -702,10 +702,16 @@ public class BasicCurlParser {
                     request.setCompressed(true);
                 } else if (option.getDescriptor().getId() == HEADER_OPT) {
                     String nameAndValue = option.getArgument(0);
-                    int indexOfSemicolon = nameAndValue.indexOf(':');
-                    String name = nameAndValue.substring(0, 
indexOfSemicolon).trim();
-                    String value = nameAndValue.substring(indexOfSemicolon + 
1).trim();
-                    request.addHeader(name, value);
+                    int indexOfColon = nameAndValue.indexOf(':');
+                    if (indexOfColon >= 0) {
+                        String name = nameAndValue.substring(0, 
indexOfColon).trim();
+                        String value = nameAndValue.substring(indexOfColon + 
1).trim();
+                        request.addHeader(name, value);
+                    } else if (nameAndValue.endsWith(";")) {
+                            request.addHeader(nameAndValue.substring(0, 
nameAndValue.length() - 1), "");
+                    } else {
+                        LOGGER.warn("Could not parse header argument [{}] as 
it didn't contain a colon nor ended with a semicolon", nameAndValue);
+                    }
                 } else if (option.getDescriptor().getId() == METHOD_OPT) {
                     String value = option.getArgument(0);
                     request.setMethod(value);
diff --git 
a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
 
b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
index 11bb1ef..83a4ad7 100644
--- 
a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
+++ 
b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
@@ -445,6 +445,16 @@ public class BasicCurlParserTest {
     }
 
     @Test
+    public void testFormWithEmptyHeader() {
+        String cmdLine = "curl 'https://example.invalid' -H 'X-Something;' ";
+        BasicCurlParser basicCurlParser = new BasicCurlParser();
+        BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
+        List<Pair<String, String>> res = request.getHeaders();
+        assertTrue(res.contains(Pair.of("X-Something", "")),
+                "With method 'parser', we should post form data: " + 
request.getFormData());
+    }
+
+    @Test
     public void testFormWithQuotedValue() {
         String cmdLine = "curl 'https://www.exaple.invalid/' "
                 + "--form 'test=\"something quoted\"'";

Reply via email to