Skip to content
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
15 changes: 15 additions & 0 deletions src/targets/shell/curl/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ runCustomFixtures({
options: {},
expected: 'urlencode.sh',
},
{
it: 'should use --data-urlencode for form-urlencoded params with special characters in values',
input: {
...applicationFormEncoded.log.entries[0].request,
postData: {
mimeType: 'application/x-www-form-urlencoded',
params: [
{ name: 'query', value: 'hello world' },
{ name: 'filter', value: 'status=active&type=user' },
],
},
} as Request,
options: {},
expected: 'urlencode-values.sh',
},
{
it: 'should send JSON-encoded data with single quotes within a HEREDOC',
input: {
Expand Down
6 changes: 2 additions & 4 deletions src/targets/shell/curl/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ export const curl: Client<CurlOptions> = {
case 'application/x-www-form-urlencoded':
if (postData.params) {
postData.params.forEach(param => {
const unencoded = param.name;
const encoded = encodeURIComponent(param.name);
const needsEncoding = encoded !== unencoded;
const name = needsEncoding ? encoded : unencoded;
const flag = binary ? '--data-binary' : needsEncoding ? '--data-urlencode' : arg('data');
const name = encoded !== param.name ? encoded : param.name;
const flag = binary ? '--data-binary' : '--data-urlencode';
push(`${flag} ${quote(`${name}=${param.value}`)}`);
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/targets/shell/curl/fixtures/application-form-encoded.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
curl --request POST \
--url https://httpbin.org/anything \
--header 'content-type: application/x-www-form-urlencoded' \
--data foo=bar \
--data hello=world
--data-urlencode foo=bar \
--data-urlencode hello=world
2 changes: 1 addition & 1 deletion src/targets/shell/curl/fixtures/custom-indentation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ curl --request POST \
@--header 'accept: application/json' \
@--header 'content-type: application/x-www-form-urlencoded' \
@--cookie 'foo=bar; bar=baz' \
@--data foo=bar
@--data-urlencode foo=bar
2 changes: 1 addition & 1 deletion src/targets/shell/curl/fixtures/full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ curl --request POST \
--header 'accept: application/json' \
--header 'content-type: application/x-www-form-urlencoded' \
--cookie 'foo=bar; bar=baz' \
--data foo=bar
--data-urlencode foo=bar
2 changes: 1 addition & 1 deletion src/targets/shell/curl/fixtures/short-options.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
curl -X POST 'https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value' -H 'accept: application/json' -H 'content-type: application/x-www-form-urlencoded' -b 'foo=bar; bar=baz' -d foo=bar
curl -X POST 'https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value' -H 'accept: application/json' -H 'content-type: application/x-www-form-urlencoded' -b 'foo=bar; bar=baz' --data-urlencode foo=bar
5 changes: 5 additions & 0 deletions src/targets/shell/curl/fixtures/urlencode-values.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl --request POST \
--url https://httpbin.org/anything \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode 'query=hello world' \
--data-urlencode 'filter=status=active&type=user'
Loading