Bug 1353535 - Copy as cURL can't copy POST without post data
MozReview-Commit-ID: EDJVsAiY6Cq
--- a/devtools/client/netmonitor/test/browser_net_curl-utils.js
+++ b/devtools/client/netmonitor/test/browser_net_curl-utils.js
@@ -36,16 +36,17 @@ add_task(function* () {
};
let data = yield createCurlData(requests.get, getLongString);
testFindHeader(data);
data = yield createCurlData(requests.post, getLongString);
testIsUrlEncodedRequest(data);
testWritePostDataTextParams(data);
+ testWriteEmptyPostDataTextParams(data);
testDataArgumentOnGeneratedCommand(data);
data = yield createCurlData(requests.multipart, getLongString);
testIsMultipartRequest(data);
testGetMultipartBoundary(data);
testMultiPartHeaders(data);
testRemoveBinaryDataFromMultipartText(data);
@@ -98,16 +99,22 @@ function testMultiPartHeaders(data) {
}
function testWritePostDataTextParams(data) {
let params = CurlUtils.writePostDataTextParams(data.postDataText);
is(params, "param1=value1¶m2=value2¶m3=value3",
"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"),
"Should return a curl command with --data");
}
function testGetMultipartBoundary(data) {
let boundary = CurlUtils.getMultipartBoundary(data);
--- a/devtools/client/shared/curl.js
+++ b/devtools/client/shared/curl.js
@@ -197,16 +197,19 @@ const CurlUtils = {
* Write out paramters from post data text.
*
* @param object postDataText
* Post data text.
* @return string
* Post data parameters.
*/
writePostDataTextParams: function (postDataText) {
+ if (!postDataText) {
+ return "";
+ }
let lines = postDataText.split("\r\n");
return lines[lines.length - 1];
},
/**
* Finds the header with the given name in the headers array.
*
* @param array headers