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",