From 671fca073679d4295075de794d7bf1b54ec69b80 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Tue, 7 Jan 2020 22:40:05 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20broken=20cURL=20import.?= =?UTF-8?q?=20Fix=20#477?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/curlparser.js | 2 +- pages/index.vue | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/assets/js/curlparser.js b/assets/js/curlparser.js index c004e46e7..fa8605d03 100644 --- a/assets/js/curlparser.js +++ b/assets/js/curlparser.js @@ -23,7 +23,7 @@ const parseCurlCommand = curlCommand => { let newlineFound = /\r|\n/.exec(curlCommand); if (newlineFound) { // remove newlines - curlCommand = curlCommand.replace(/\\\r|\\\n/g, ""); + curlCommand = curlCommand.replace(/\r|\n/g, ""); } // yargs parses -XPOST as separate arguments. just prescreen for it. curlCommand = curlCommand.replace(/ -XPOST/, " -X POST"); diff --git a/pages/index.vue b/pages/index.vue index fcd78dd34..39b3131f7 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1461,26 +1461,26 @@ export default { return requestString.join(""); } else if (this.requestType === "cURL") { const requestString = []; - requestString.push("curl -X " + this.method + " \\\n"); + requestString.push("curl -X " + this.method + " \n"); requestString.push( - " '" + this.url + this.pathName + this.queryString + "' \\\n" + " '" + this.url + this.pathName + this.queryString + "' \n" ); if (this.auth === "Basic Auth") { const basic = this.httpUser + ":" + this.httpPassword; requestString.push( " -H 'Authorization: Basic " + window.btoa(unescape(encodeURIComponent(basic))) + - "' \\\n" + "' \n" ); } else if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") { requestString.push( - " -H 'Authorization: Bearer " + this.bearerToken + "' \\\n" + " -H 'Authorization: Bearer " + this.bearerToken + "' \n" ); } if (this.headers) { this.headers.forEach(element => { requestString.push( - " -H '" + element.key + ": " + element.value + "' \\\n" + " -H '" + element.key + ": " + element.value + "' \n" ); }); } @@ -1489,14 +1489,14 @@ export default { ? this.rawParams : this.rawRequestBody; requestString.push( - " -H 'Content-Length: " + requestBody.length + "' \\\n" + " -H 'Content-Length: " + requestBody.length + "' \n" ); requestString.push( - " -H 'Content-Type: " + this.contentType + "; charset=utf-8' \\\n" + " -H 'Content-Type: " + this.contentType + "; charset=utf-8' \n" ); - requestString.push(" -d '" + requestBody + "' \\\n"); + requestString.push(" -d '" + requestBody + "' \n"); } - return requestString.join("").slice(0, -3); + return requestString.join("").slice(0, -2); } } }, @@ -2015,11 +2015,13 @@ export default { this.url = url.origin; this.path = url.pathname; this.headers = []; - for (const key of Object.keys(parsedCurl.headers)) { - this.$store.commit("addHeaders", { - key: key, - value: parsedCurl.headers[key] - }); + if (parsedCurl.headers) { + for (const key of Object.keys(parsedCurl.headers)) { + this.$store.commit("addHeaders", { + key: key, + value: parsedCurl.headers[key] + }); + } } this.method = parsedCurl.method.toUpperCase(); if (parsedCurl["data"]) {