Bug 64636

Summary: Curl importer can't parse empty data argument
Product: JMeter Reporter: Felix Schumacher <felix.schumacher>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: NEW ---    
Severity: normal CC: p.mouawad
Priority: P2    
Version: Nightly (Please specify date)   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Felix Schumacher 2020-08-01 14:36:29 UTC
If you try to import a curl script with a blank argument for a switch that expects an argument, the importer will throw an exception instead of using an empty string as data.

Take for example the curl script:
  
  curl --data '' https://example.invalid

JMeter will currently throw an exception on importing:

2020-08-01 16:29:18,878 ERROR o.a.j.p.h.g.a.ParseCurlCommandAction: Error creating test plan from cURL command:curl --data '' https://example.invalid, error:null
java.net.MalformedURLException: null
	at java.net.URL.<init>(URL.java:627) ~[?:1.8.0_201]
	at java.net.URL.<init>(URL.java:490) ~[?:1.8.0_201]
	at java.net.URL.<init>(URL.java:439) ~[?:1.8.0_201]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.createSampler(ParseCurlCommandAction.java:286) ~[ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.createHttpRequest(ParseCurlCommandAction.java:260) ~[ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.createTestPlan(ParseCurlCommandAction.java:222) ~[ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.actionPerformed(ParseCurlCommandAction.java:624) [ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) [?:1.8.0_201]
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) [?:1.8.0_201]
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) [?:1.8.0_201]
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) [?:1.8.0_201]
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) [?:1.8.0_201]
	at java.awt.Component.processMouseEvent(Component.java:6539) [?:1.8.0_201]
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) [?:1.8.0_201]
	at java.awt.Component.processEvent(Component.java:6304) [?:1.8.0_201]
	at java.awt.Container.processEvent(Container.java:2239) [?:1.8.0_201]
	at java.awt.Component.dispatchEventImpl(Component.java:4889) [?:1.8.0_201]
	at java.awt.Container.dispatchEventImpl(Container.java:2297) [?:1.8.0_201]
	at java.awt.Component.dispatchEvent(Component.java:4711) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476) [?:1.8.0_201]
	at java.awt.Container.dispatchEventImpl(Container.java:2283) [?:1.8.0_201]
	at java.awt.Window.dispatchEventImpl(Window.java:2746) [?:1.8.0_201]
	at java.awt.Component.dispatchEvent(Component.java:4711) [?:1.8.0_201]
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) [?:1.8.0_201]
	at java.awt.EventQueue.access$500(EventQueue.java:97) [?:1.8.0_201]
	at java.awt.EventQueue$3.run(EventQueue.java:709) [?:1.8.0_201]
	at java.awt.EventQueue$3.run(EventQueue.java:703) [?:1.8.0_201]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) [?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84) [?:1.8.0_201]
	at java.awt.EventQueue$4.run(EventQueue.java:733) [?:1.8.0_201]
	at java.awt.EventQueue$4.run(EventQueue.java:731) [?:1.8.0_201]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) [?:1.8.0_201]
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:730) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) [?:1.8.0_201]
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) [?:1.8.0_201]
Caused by: java.lang.NullPointerException
	at java.net.URL.<init>(URL.java:532) ~[?:1.8.0_201]
	... 42 more

If we switch the parameters around and use the data switch with a blank argument at the end of the line like:

  curl https://example.invalid --data ''

we get the following exception:
2020-08-01 16:34:08,396 ERROR o.a.j.p.h.g.a.ParseCurlCommandAction: Error creating test plan from cURL command list:[curl https://example.invalid --data '']
java.lang.IllegalArgumentException: Unexpected format for command line:curl https://example.invalid --data '', error:Missing argument to option --data
	at org.apache.jmeter.protocol.http.curl.BasicCurlParser.parse(BasicCurlParser.java:797) ~[ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.parseCommands(ParseCurlCommandAction.java:665) ~[ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction.actionPerformed(ParseCurlCommandAction.java:614) [ApacheJMeter_http.jar:5.3.1-SNAPSHOT]
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) [?:1.8.0_201]
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) [?:1.8.0_201]
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) [?:1.8.0_201]
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) [?:1.8.0_201]
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) [?:1.8.0_201]
	at java.awt.Component.processMouseEvent(Component.java:6539) [?:1.8.0_201]
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) [?:1.8.0_201]
	at java.awt.Component.processEvent(Component.java:6304) [?:1.8.0_201]
	at java.awt.Container.processEvent(Container.java:2239) [?:1.8.0_201]
	at java.awt.Component.dispatchEventImpl(Component.java:4889) [?:1.8.0_201]
	at java.awt.Container.dispatchEventImpl(Container.java:2297) [?:1.8.0_201]
	at java.awt.Component.dispatchEvent(Component.java:4711) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) [?:1.8.0_201]
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476) [?:1.8.0_201]
	at java.awt.Container.dispatchEventImpl(Container.java:2283) [?:1.8.0_201]
	at java.awt.Window.dispatchEventImpl(Window.java:2746) [?:1.8.0_201]
	at java.awt.Component.dispatchEvent(Component.java:4711) [?:1.8.0_201]
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) [?:1.8.0_201]
	at java.awt.EventQueue.access$500(EventQueue.java:97) [?:1.8.0_201]
	at java.awt.EventQueue$3.run(EventQueue.java:709) [?:1.8.0_201]
	at java.awt.EventQueue$3.run(EventQueue.java:703) [?:1.8.0_201]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) [?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84) [?:1.8.0_201]
	at java.awt.EventQueue$4.run(EventQueue.java:733) [?:1.8.0_201]
	at java.awt.EventQueue$4.run(EventQueue.java:731) [?:1.8.0_201]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_201]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) [?:1.8.0_201]
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:730) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:1.8.0_201]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) [?:1.8.0_201]
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) [?:1.8.0_201]

Both exceptions have the same origin. The used parser will skip the blank argument and our logic is therefore missing the argument.