From e070f5619375815ba03b06fa305015e884fdc76f Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Thu, 21 Mar 2024 11:49:58 -0400 Subject: [PATCH 1/3] fix(curl,shell): shell quoting on @file --- src/targets/shell/curl/client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/targets/shell/curl/client.ts b/src/targets/shell/curl/client.ts index d0ba163f..54d65a5c 100644 --- a/src/targets/shell/curl/client.ts +++ b/src/targets/shell/curl/client.ts @@ -122,13 +122,16 @@ export const curl: Client = { case 'multipart/form-data': postData.params?.forEach(param => { let post = ''; + // If the parameter is a filename, we want to put shell quotes around + // it rather than URL quoting it. Curl wants `file='@img copy.jpg'` + // not `file=@img%20copy.jpg`, which it will fail to find if (param.fileName) { - post = `${param.name}=@${param.fileName}`; + post = `${param.name}='@${param.fileName}'`; } else { - post = `${param.name}=${param.value}`; + post = quote(`${param.name}=${param.value}`); } - push(`${arg('form')} ${quote(post)}`); + push(`${arg('form')} ${post}`); }); break; From d016f2bc5219a791417771ef0bd5c7979a4f9daf Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Thu, 21 Mar 2024 11:54:25 -0400 Subject: [PATCH 2/3] update fixtures --- src/targets/shell/curl/fixtures/multipart-data.sh | 4 ++-- src/targets/shell/curl/fixtures/multipart-file.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/targets/shell/curl/fixtures/multipart-data.sh b/src/targets/shell/curl/fixtures/multipart-data.sh index 693fabf3..73185dfb 100755 --- a/src/targets/shell/curl/fixtures/multipart-data.sh +++ b/src/targets/shell/curl/fixtures/multipart-data.sh @@ -1,5 +1,5 @@ curl --request POST \ --url https://httpbin.org/anything \ --header 'content-type: multipart/form-data' \ - --form foo=@src/fixtures/files/hello.txt \ - --form 'bar=Bonjour le monde' \ No newline at end of file + --form foo='@src/fixtures/files/hello.txt' \ + --form 'bar=Bonjour le monde' diff --git a/src/targets/shell/curl/fixtures/multipart-file.sh b/src/targets/shell/curl/fixtures/multipart-file.sh index 5abea7b7..064a124b 100755 --- a/src/targets/shell/curl/fixtures/multipart-file.sh +++ b/src/targets/shell/curl/fixtures/multipart-file.sh @@ -1,4 +1,4 @@ curl --request POST \ --url https://httpbin.org/anything \ --header 'content-type: multipart/form-data' \ - --form foo=@src/fixtures/files/hello.txt \ No newline at end of file + --form foo='@src/fixtures/files/hello.txt' From 5844bb036fecf5304a1c93ecb9f418e7dea81794 Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Thu, 21 Mar 2024 11:57:21 -0400 Subject: [PATCH 3/3] chore: update the fixtures properly --- src/targets/shell/curl/fixtures/multipart-data.sh | 2 +- src/targets/shell/curl/fixtures/multipart-file.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targets/shell/curl/fixtures/multipart-data.sh b/src/targets/shell/curl/fixtures/multipart-data.sh index 73185dfb..42d3d3f6 100755 --- a/src/targets/shell/curl/fixtures/multipart-data.sh +++ b/src/targets/shell/curl/fixtures/multipart-data.sh @@ -2,4 +2,4 @@ curl --request POST \ --url https://httpbin.org/anything \ --header 'content-type: multipart/form-data' \ --form foo='@src/fixtures/files/hello.txt' \ - --form 'bar=Bonjour le monde' + --form 'bar=Bonjour le monde' \ No newline at end of file diff --git a/src/targets/shell/curl/fixtures/multipart-file.sh b/src/targets/shell/curl/fixtures/multipart-file.sh index 064a124b..6ea03380 100755 --- a/src/targets/shell/curl/fixtures/multipart-file.sh +++ b/src/targets/shell/curl/fixtures/multipart-file.sh @@ -1,4 +1,4 @@ curl --request POST \ --url https://httpbin.org/anything \ --header 'content-type: multipart/form-data' \ - --form foo='@src/fixtures/files/hello.txt' + --form foo='@src/fixtures/files/hello.txt' \ No newline at end of file