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

Add curl argument: --data-urlencode #1009

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ We add the capability to directly run [curl request](https://curl.haxx.se/) in R
* -I, --head
* -b, --cookie(no cookie jar file support)
* -u, --user(Basic auth support only)
* -d, --data, --data-ascii,--data-binary, --data-raw
* -d, --data, --data-ascii,--data-binary, --data-raw, --data-urlencode

## Copy Request As cURL
Sometimes you may want to get the curl format of an http request quickly and save it to clipboard, just pressing `F1` and then selecting/typing `Rest Client: Copy Request As cURL` or simply right-click in the editor, and select `Copy Request As cURL`.
Expand Down
19 changes: 14 additions & 5 deletions src/utils/curlRequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ export class CurlRequestParser implements RequestParser {
}

// parse body
let body = parsedArguments.d || parsedArguments.data || parsedArguments['data-ascii'] || parsedArguments['data-binary'] || parsedArguments['data-raw'];
if (Array.isArray(body)) {
body = body.join('&');
} else if (body !== undefined) {
body = body.toString();
const dataKeys = ['d', 'data', 'data-ascii', 'data-binary', 'data-raw', 'data-urlencode'];
const datakey = dataKeys.find(key => !!parsedArguments[key])
let body;
if (datakey) {
body = parsedArguments[datakey];
if (Array.isArray(body)) {
body = body.join('&');
} else {
if (!!parsedArguments['data-urlencode']) {
body = encodeURI(body.toString());
} else {
body = body.toString();
}
}
}

if (typeof body === 'string' && body[0] === '@') {
Expand Down