Open Bug 1097908 Opened 10 years ago Updated 2 years ago

"Copy as cURL" incorrectly escapes strings for Windows command prompt

Categories

(DevTools :: Netmonitor, defect)

defect

Tracking

(Not tracked)

People

(Reporter: emorley, Unassigned)

References

(Blocks 1 open bug)

Details

Whilst I'd ideally use "Copy as cURL" with my msys shell, I'm falling back to using the Windows command prompt due to bug 1097836.

However the windows-compatible cURL command we generate doesn't seem to work correctly.

For the request in bug 1097836 comment 0, using the resultant "Copy as cURL" output (I had to add -k to disable SSL cert verification):

C:\Users\Ed\Desktop\curl-7.39.0-ssl-sspi-zlib-static-bin-w32>curl -k "https://bugzilla.mozilla.org/bzapi/bug/1069823?username=foo"%"40bar.com&password=baz" -X PUT -H "Host: bugzilla.mozilla.org" -H "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" -H "Accept: application/json" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "DNT: 1" -H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://tbpl.mozilla.org/mcmerge/?tree=mozilla-inbound&cset=c6fa46d62293" -H "Origin: https://tbpl.mozilla.org" -H "Connection: keep-alive" --data "{""comments"":[{""creation_time"":""2014-11-12T18:20:35.076Z"",""creator"":{""email"":""foo@bar.com""},""is_private"":0,""text"":""https://hg.mozilla.org/integration/mozilla-inbound/rev/c6fa46d62293""}],""id"":""1069823"",""whiteboard"":"""",""assigned_to"":{""name"":""eflores@snip.com""}}"


Gives:

{"documentation":"https://wiki.mozilla.org/Bugzilla:BzAPI","error":true,"code":32000,"message":"Could not parse the 'params' argument as valid JSON. Error: ':' expected, at character offset 191 (before \",\"assigned_to:{name:...\") at /data/www/bugzilla.mozilla.org/Bugzilla/WebService/Server/REST.pm line 360. Value:"}

Replacing:
""whiteboard"":""""

With:
""whiteboard"":""foo""

Fixes the first error, but gives:

{"documentation":"https://wiki.mozilla.org/Bugzilla:BzAPI","error":true,"code":32000,"message":"Could not parse the 'params' argument as valid JSON. Error: unexpected end of string while parsing JSON string, at character offset 230 (before \"(end of string)\") at /data/www/bugzilla.mozilla.org/Bugzilla/WebService/Server/REST.pm line 360. Value:"}

In fact, using POSIX style escaping (ie: `\"` instead of `""`) actually works correctly:

curl -k "https://bugzilla.mozilla.org/bzapi/bug/1069823?username=foo"%"40bar.com&password=baz" -X PUT -H "Host: bugzilla.mozilla.org" -H "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" -H "Accept: application/json" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "DNT: 1" -H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://tbpl.mozilla.org/mcmerge/?tree=mozilla-inbound&cset=c6fa46d62293" -H "Origin: https://tbpl.mozilla.org" -H "Connection: keep-alive" --data "{\"comments\":[{\"creation_time\":\"2014-11-12T18:20:35.076Z\",\"creator\":{\"email\":\"foo@bar.com\"},\"is_private\":0,\"text\":\"https://hg.mozilla.org/integration/mozilla-inbound/rev/c6fa46d62293\"}],\"id\":\"1069823\",\"whiteboard\":\"\",\"assigned_to\":{\"name\":\"eflores@snip.com\"}}"

{"documentation":"https://wiki.mozilla.org/Bugzilla:BzAPI","error":true,"code":300,"message":"The username or password you entered is not valid."}
No longer depends on: 1097836
Product: Firefox → DevTools
Could this be a discrepancy in command line handling between MSYS cURL and native Windows cURL? I have never figured out shell escaping rules for Windows which work universally in all programs, because (if I understand correctly) at the core Windows only passes a single argument, which is parsed by programs in an application-specific manner (not all programs necessarily use CommandLineToArgvW).
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.