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 #1159

Liyas Thomas005db4d0e898
diff --git a/assets/js/curlparser.js b/assets/js/curlparser.js
index a0d097eb1..5718fefff 100644
--- a/assets/js/curlparser.js
+++ b/assets/js/curlparser.js
@@ -1,6 +1,7 @@
import * as cookie from "cookie"
import * as URL from "url"
import * as querystring from "querystring"
+import parser from "yargs-parser"
/**
* given this: [ 'msg1=value1', 'msg2=value2' ]
@@ -20,10 +21,10 @@ const joinDataArguments = (dataArguments) => {
}
const parseCurlCommand = (curlCommand) => {
- let newlineFound = /\r|\n/.exec(curlCommand)
+ let newlineFound = /\r?\n|\r/.exec(curlCommand)
if (newlineFound) {
// remove newlines
- curlCommand = curlCommand.replace(/\r|\n/g, "")
+ curlCommand = curlCommand.replace(/\r?\n|\r/g, "")
}
// yargs parses -XPOST as separate arguments. just prescreen for it.
curlCommand = curlCommand.replace(/ -XPOST/, " -X POST")
@@ -32,10 +33,10 @@ const parseCurlCommand = (curlCommand) => {
curlCommand = curlCommand.replace(/ -XPATCH/, " -X PATCH")
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
curlCommand = curlCommand.trim()
- let parsedArguments = require("yargs-parser")(curlCommand)
+ let parsedArguments = parser(curlCommand)
let cookieString
let cookies
- let url = parsedArguments._[1]
+ let url = parsedArguments._[2]
if (!url) {
for (let argName in parsedArguments) {
if (typeof parsedArguments[argName] === "string") {
diff --git a/pages/index.vue b/pages/index.vue
index 799cc5f01..158274ab5 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -2413,6 +2413,7 @@ export default {
const { origin, pathname } = new URL(parsedCurl.url.replace(/"/g, "").replace(/'/g, ""))
this.url = origin
this.path = pathname
+ this.uri = this.url + this.path
this.headers = []
if (parsedCurl.headers) {
for (const key of Object.keys(parsedCurl.headers)) {