From 18fa48d27ccaba57c9b7b2e566df0f6ed85ad6d2 Mon Sep 17 00:00:00 2001 From: Stefan Yohansson Date: Tue, 4 Apr 2017 18:35:29 -0300 Subject: [PATCH] Bug 1353535 - Fix "copy as curl" POST request without json data. r=gasolin --HG-- extra : rebase_source : 35d42a108df7e2241f8b0740a6ca8bc3997bdf13 --- devtools/client/netmonitor/test/browser_net_curl-utils.js | 7 +++++++ devtools/client/shared/curl.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/devtools/client/netmonitor/test/browser_net_curl-utils.js b/devtools/client/netmonitor/test/browser_net_curl-utils.js index bc7bb5bb0934..e667cf514b17 100644 --- a/devtools/client/netmonitor/test/browser_net_curl-utils.js +++ b/devtools/client/netmonitor/test/browser_net_curl-utils.js @@ -41,6 +41,7 @@ add_task(function* () { data = yield createCurlData(requests.post, getLongString); testIsUrlEncodedRequest(data); testWritePostDataTextParams(data); + testWriteEmptyPostDataTextParams(data); testDataArgumentOnGeneratedCommand(data); data = yield createCurlData(requests.multipart, getLongString); @@ -103,6 +104,12 @@ function testWritePostDataTextParams(data) { "Should return a serialized representation of the request parameters"); } +function testWriteEmptyPostDataTextParams(data) { + let params = CurlUtils.writePostDataTextParams(null); + is(params, "", + "Should return a empty string when no parameters provided"); +} + function testDataArgumentOnGeneratedCommand(data) { let curlCommand = Curl.generateCommand(data); ok(curlCommand.includes("--data"), diff --git a/devtools/client/shared/curl.js b/devtools/client/shared/curl.js index bab330807e48..13536ef98a63 100644 --- a/devtools/client/shared/curl.js +++ b/devtools/client/shared/curl.js @@ -202,6 +202,9 @@ const CurlUtils = { * Post data parameters. */ writePostDataTextParams: function (postDataText) { + if (!postDataText) { + return ""; + } let lines = postDataText.split("\r\n"); return lines[lines.length - 1]; },