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
This commit is contained in:
@@ -23,7 +23,7 @@ export default function curl( request ){
|
||||
for( let [ k,v ] of request.get("body").entrySeq()) {
|
||||
curlified.push( "-F" )
|
||||
if (v instanceof win.File) {
|
||||
curlified.push( `"${k}=@${v.name};type=${v.type}"` )
|
||||
curlified.push( `"${k}=@${v.name}${v.type ? `;type=${v.type}` : ""}"` )
|
||||
} else {
|
||||
curlified.push( `"${k}=${v}"` )
|
||||
}
|
||||
|
||||
@@ -163,6 +163,26 @@ describe("curlify", function() {
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"")
|
||||
})
|
||||
|
||||
it("should print a curl without form data type if type is unknown", function() {
|
||||
var file = new win.File()
|
||||
file.name = "file.txt"
|
||||
file.type = ""
|
||||
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
headers: { "content-type": "multipart/form-data" },
|
||||
body: {
|
||||
id: "123",
|
||||
file
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"")
|
||||
})
|
||||
|
||||
it("prints a curl post statement from an object", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
|
||||
Reference in New Issue
Block a user