Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Windows commands created using "Copy as cURL (cmd)" #143

Open
Revadike opened this issue Jul 30, 2019 · 11 comments
Open

Support Windows commands created using "Copy as cURL (cmd)" #143

Revadike opened this issue Jul 30, 2019 · 11 comments

Comments

@Revadike
Copy link

In cmd curl, this is an escaped thing: --data "a=b^&c=d^&e=f^&h=i^&j=k^&l=m"
In this case: ^& should be &.
In other words, you'll have to unescape the string.

@NickCarneiro
Copy link
Member

I don't see this escaping behavior on my machine. Can you provide a full curl command?
Command:
curl -v --data "a=b^&c=d^&e=f^&h=i^&j=k^&l=m" http://localhost:3005/page

Data received by server:

curl1

@Revadike
Copy link
Author

Steps to reproduce:

  1. Go to network tab in dev tools
  2. Submit form
  3. Copy request as cURL (cmd)
  4. Observe how the body/data of the copied cURL is escaped (for cmd)
  5. Use your website to convert cURL to node.js request
  6. Data/body remains escaped for cmd

@jgroom33
Copy link
Collaborator

Is ^ an escape character?

@Revadike
Copy link
Author

@jgroom33
Copy link
Collaborator

Oh... ^ is escape character in Windows environment.

On mac and Linux, there is no option to export as cmd.

Why not use export as bash?

@Revadike
Copy link
Author

Revadike commented Aug 15, 2019

I dunno. I haven't really used it, tbh. I'm just pointing out this case. Perhaps you want to handle it.

@jgroom33
Copy link
Collaborator

Perhaps.
I think generally Linux use cases are prioritized. If there is a work-around in Windows, that is preferred. If there is no work-around, then a fix is definitely warranted.

Is cmd output only used in powershell/cmd? I.e. does bash output not work in those environment?

@Revadike
Copy link
Author

If you mean, if it has to be escaped for windows cmd usage, I believe yes.

@jgroom33
Copy link
Collaborator

jgroom33 commented Aug 15, 2019

This is not solvable without adding a handling for a new input language of curl cmd
This project only supports input language of curl bash
I recommend closing this as "won't fix"

@NickCarneiro
Copy link
Member

@jgroom33 I would also consider cmd curl out of scope, BUT @cf512 already has an in-progress PR to support this kind of input. The only thing left is to separate out the code path into a new input language parser. I'm meeting with him today to see if he wants to proceed.

@Revadike Thanks for providing a clear example.

@verhovsky verhovsky changed the title Unescape cmd curl data string Support Windows commands created using "Copy as cURL (cmd)" Sep 29, 2021
@verhovsky
Copy link
Member

verhovsky commented Sep 29, 2021

To support Windows cmd, someone needs to write a tree-sitter grammar for it (also see How to write a tree-sitter grammar in an afternoon). Anyone interested in doing that could take the bash tree-sitter grammar as a starting point. You can also look at the actual Chrome code that generates these cmd curl commands here

https://github.com/ChromeDevTools/devtools-frontend/blob/04d4b64221e472bcbd5d1de16bef59c2cb9f8d02/front_end/panels/network/NetworkLogView.ts#L2033

Until/unless someone writes a grammar, the most we can do is improve the screenshot on the website so that Windows users have a chance to know that they need to click "Copy as cURL (bash)" instead of "Copy as cURL (cmd)". We could also detect if that's what happened (something like input.count('^') > 3 lol) and print a warning.

@verhovsky verhovsky pinned this issue Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants