Skip to content

Commit 29e859d

Browse files
authored
fix(curl,shell): shell quoting on @file (#221)
## 🧰 Changes Fix shell quoting on curl's @file parameter ## 🧬 QA & Testing - save an image file to the file name `image copy.jpg`, then run: `curl https://httpbingo.org/anything -X POST --form file='@image copy.jpg'` note that what we currently produce is: `curl https://httpbingo.org/anything -X POST --form file=@image%20copy.jpg` and that that does not work
1 parent ebc85d3 commit 29e859d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/targets/shell/curl/client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,16 @@ export const curl: Client<CurlOptions> = {
122122
case 'multipart/form-data':
123123
postData.params?.forEach(param => {
124124
let post = '';
125+
// If the parameter is a filename, we want to put shell quotes around
126+
// it rather than URL quoting it. Curl wants `file='@img copy.jpg'`
127+
// not `file=@img%20copy.jpg`, which it will fail to find
125128
if (param.fileName) {
126-
post = `${param.name}=@${param.fileName}`;
129+
post = `${param.name}='@${param.fileName}'`;
127130
} else {
128-
post = `${param.name}=${param.value}`;
131+
post = quote(`${param.name}=${param.value}`);
129132
}
130133

131-
push(`${arg('form')} ${quote(post)}`);
134+
push(`${arg('form')} ${post}`);
132135
});
133136
break;
134137

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
curl --request POST \
22
--url https://httpbin.org/anything \
33
--header 'content-type: multipart/form-data' \
4-
--form foo=@src/fixtures/files/hello.txt \
4+
--form foo='@src/fixtures/files/hello.txt' \
55
--form 'bar=Bonjour le monde'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
curl --request POST \
22
--url https://httpbin.org/anything \
33
--header 'content-type: multipart/form-data' \
4-
--form foo=@src/fixtures/files/hello.txt
4+
--form foo='@src/fixtures/files/hello.txt'

0 commit comments

Comments
 (0)