agrostar / zzapi-vscode

VS Code extension for zzapi - an API testing and documentation framework
MIT License
3 stars 0 forks source link

quotes have to be escaped in "Show Curl" output #19

Open vasan-agrostar opened 1 week ago

vasan-agrostar commented 1 week ago

I have a parameter which has a quote in it. (I have to access this particular API: https://developer.freshdesk.com/api/#filter_tickets)

The Run Request runs fine, but when I click on "Show Curl", the quotes appear as is, thus terminating the open quote of the URL.

curl -X GET -H 'user-agent: zzAPI-vscode/2.3.0' -H 'authorization: Basic XXX' -k -i 'https://domain.freshdesk.com/api/v2/search/tickets?query=%22type%3A'Saathi%20Churn'%20AND%20created_at%3A'2024-05-31'%22&page=1'
vasan-agrostar commented 1 week ago

Also, can we drop the user-agent header? curl will send its own user-agent header, and we should respect that.

Varun0157 commented 1 week ago

I understand the issue, but can you clarify what you mean by "quotes have to be escaped"? I interpret it to mean you want the quotes wrapping the headers, url, etc. to be escaped (\'...\' instead of '...') while creating the string, but I fail to see how that would help prevent cURL from misinterpreting the command, because the output command would still be the same, right?

The fix I see is just to replace the single quotes on creation with double quotes, but that may not be general enough.

vasan-agrostar commented 1 week ago

I think even \' won't work. BTW, it is the shell that interprets this, not curl. For the shell, anything within single quotes, including \ will be interpreted literally.

We could use double-quotes instead of single quotes, but that would mean lot of escaping. We will have to escape ", $, * at the minimum, because these have special meaning in the shell.

Even though it is not required to URL encode the single quote using %, we can do that and it will work. So replace all ' in the cURL command with %27 (even though the zzAPI request will have the single-quote as is).

Postman seems to do the same.

Varun0157 commented 1 week ago

The node module replaces single quotes with %27, while the extension removes the zzAPI user-agent while calling constructCurl in the module.