Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

🐛 Fixed broken cURL import. Fix #477

Liyas Thomas671fca073679
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"]) {