Closed Bug 1097836 Opened 5 years ago Closed 2 months ago

Give users on Windows the choice between POSIX and Windows escaped "Copy as cURL" commands

Categories

(DevTools :: Netmonitor, defect, P3)

defect

Tracking

(firefox70 fixed)

RESOLVED FIXED
Firefox 70
Tracking Status
firefox70 --- fixed

People

(Reporter: emorley, Assigned: real.trd)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

For the following request seen in net monitor (trying to reproduce another issue):

Request URL:
https://bugzilla.mozilla.org/bzapi/bug/1069823?username=foo%40bar.com&password=baz

Request method:
PUT

Request headers:
Host: bugzilla.mozilla.org
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Content-Type: application/json; charset=UTF-8
Referer: https://tbpl.mozilla.org/mcmerge/?tree=mozilla-inbound&cset=c6fa46d62293
Content-Length: 261
Origin: https://tbpl.mozilla.org
Connection: keep-alive

Request payload:
{"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"}}

Using "Copy as cURL" gives:

curl "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""}}"

But using this in my console gives a response of:

{"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 1 (before \"comments:[{creation_...\") at /data/www/bugzilla.mozilla.org/Bugzilla/WebService/Server/REST.pm line 360. Value:"}

$ curl --version
curl 7.39.0 (x86_64-pc-msys) libcurl/7.39.0 OpenSSL/1.0.1j zlib/1.2.8 libidn/1.29 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: Debug IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP Metalink

It seems like we're trying to escape `"` using `""`, rather than `\"`.
Ok so this seems by design...

The escaping is varied by OS:
http://mxr.mozilla.org/mozilla-central/source/browser/devtools/shared/Curl.jsm#70

On Windows we use:
http://mxr.mozilla.org/mozilla-central/source/browser/devtools/shared/Curl.jsm#380

The problem is that I would imagine a sizable number of developers do not use the Windows command prompt, and instead use msys/cygwin or say a VM for development (but test in a browser outside the VM), and so still want the POSIX escaped cURL command.

Perhaps a solution here is on Windows only, we show two options:
"Copy as cURL (Windows)"
"Copy as cURL (POSIX)"

So the user (a) knows there is an intentional platform difference in output, and (b) is able to choose the POSIX if they need.

I know two menu items isn't ideal, but (a) it doesn't affect non-windows, and (b) someone using this context menu in the netmonitor is pretty deep in devtools and not someone who should be put off by option-overload, (c) half the problem here is awareness (that Windows users are expected to use cmd.exe) which would not be helped by making this an about:config pref.
Summary: The "Copy as cURL" feature incorrectly escapes the POST request payload → Unable to generate a POSIX-style escaped string using "Copy as cURL" on Windows
Summary: Unable to generate a POSIX-style escaped string using "Copy as cURL" on Windows → Give users on Windows the choice between POSIX and Windows escaped "Copy as cURL" commands
Blocks: 1097908
No longer blocks: 1097908
Product: Firefox → DevTools

Hi, this feature would be very useful. I'd like to work on it. Can I make a patch?

Sure, assigned to you.
Honza

Assignee: nobody → real.trd
Status: NEW → ASSIGNED
Priority: -- → P3

Hi Stanislav, do you need any help to work on this bug? It's been a month so I was wondering if you were blocked and needed help, or if you weren't planning on working on this bug anymore.
In case you haven't yet read our docs, you can find them here: https://docs.firefox-dev.tools/

Flags: needinfo?(real.trd)

(In reply to Patrick Brosset <:pbro> from comment #4)

Hi Stanislav, do you need any help to work on this bug? It's been a month so I was wondering if you were blocked and needed help, or if you weren't planning on working on this bug anymore.
In case you haven't yet read our docs, you can find them here: https://docs.firefox-dev.tools/

Hi, Patrick. I have attached my patch for this bug at phabricator (Update of the one of the tests taken a bit more time than I thought)

Flags: needinfo?(real.trd)
Pushed by jodvarko@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/41b21e18ff5a
Give users on Windows the choice between POSIX and Windows escaped "Copy as cURL" commands. r=Honza
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 70
You need to log in before you can comment on or make changes to this bug.