From a40edea3f1325d529ee4b5bbe80779d96b3a2f84 Mon Sep 17 00:00:00 2001 From: Kristofer Wright Date: Fri, 23 Nov 2018 15:22:42 -0800 Subject: [PATCH] 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 --- src/core/curlify.js | 2 +- test/core/curlify.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core/curlify.js b/src/core/curlify.js index 328830c1..a1385f5f 100644 --- a/src/core/curlify.js +++ b/src/core/curlify.js @@ -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}"` ) } diff --git a/test/core/curlify.js b/test/core/curlify.js index 8084bd6e..1467620e 100644 --- a/test/core/curlify.js +++ b/test/core/curlify.js @@ -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",