Skip to content

Commit a40edea

Browse files
Kristofer Wrightshockey
authored andcommitted
fix: only append type flag to curl if type is defined (via #5041)
* issue 5040: only append type to formData file if defined * errant whitespace removal: * conform to code style * code style * use template string in nested type ternary operator
1 parent 88e2c9a commit a40edea

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/core/curlify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function curl( request ){
2323
for( let [ k,v ] of request.get("body").entrySeq()) {
2424
curlified.push( "-F" )
2525
if (v instanceof win.File) {
26-
curlified.push( `"${k}=@${v.name};type=${v.type}"` )
26+
curlified.push( `"${k}=@${v.name}${v.type ? `;type=${v.type}` : ""}"` )
2727
} else {
2828
curlified.push( `"${k}=${v}"` )
2929
}

test/core/curlify.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ describe("curlify", function() {
163163
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"[email protected];type=text/plain\"")
164164
})
165165

166+
it("should print a curl without form data type if type is unknown", function() {
167+
var file = new win.File()
168+
file.name = "file.txt"
169+
file.type = ""
170+
171+
var req = {
172+
url: "http://example.com",
173+
method: "POST",
174+
headers: { "content-type": "multipart/form-data" },
175+
body: {
176+
id: "123",
177+
file
178+
}
179+
}
180+
181+
let curlified = curl(Im.fromJS(req))
182+
183+
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"[email protected]\"")
184+
})
185+
166186
it("prints a curl post statement from an object", function() {
167187
var req = {
168188
url: "http://example.com",

0 commit comments

Comments
 (0)