Fixed #1159
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import * as cookie from "cookie"
|
import * as cookie from "cookie"
|
||||||
import * as URL from "url"
|
import * as URL from "url"
|
||||||
import * as querystring from "querystring"
|
import * as querystring from "querystring"
|
||||||
|
import parser from "yargs-parser"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* given this: [ 'msg1=value1', 'msg2=value2' ]
|
* given this: [ 'msg1=value1', 'msg2=value2' ]
|
||||||
@@ -20,10 +21,10 @@ const joinDataArguments = (dataArguments) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parseCurlCommand = (curlCommand) => {
|
const parseCurlCommand = (curlCommand) => {
|
||||||
let newlineFound = /\r|\n/.exec(curlCommand)
|
let newlineFound = /\r?\n|\r/.exec(curlCommand)
|
||||||
if (newlineFound) {
|
if (newlineFound) {
|
||||||
// remove newlines
|
// 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.
|
// yargs parses -XPOST as separate arguments. just prescreen for it.
|
||||||
curlCommand = curlCommand.replace(/ -XPOST/, " -X POST")
|
curlCommand = curlCommand.replace(/ -XPOST/, " -X POST")
|
||||||
@@ -32,10 +33,10 @@ const parseCurlCommand = (curlCommand) => {
|
|||||||
curlCommand = curlCommand.replace(/ -XPATCH/, " -X PATCH")
|
curlCommand = curlCommand.replace(/ -XPATCH/, " -X PATCH")
|
||||||
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
|
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
|
||||||
curlCommand = curlCommand.trim()
|
curlCommand = curlCommand.trim()
|
||||||
let parsedArguments = require("yargs-parser")(curlCommand)
|
let parsedArguments = parser(curlCommand)
|
||||||
let cookieString
|
let cookieString
|
||||||
let cookies
|
let cookies
|
||||||
let url = parsedArguments._[1]
|
let url = parsedArguments._[2]
|
||||||
if (!url) {
|
if (!url) {
|
||||||
for (let argName in parsedArguments) {
|
for (let argName in parsedArguments) {
|
||||||
if (typeof parsedArguments[argName] === "string") {
|
if (typeof parsedArguments[argName] === "string") {
|
||||||
|
|||||||
@@ -2413,6 +2413,7 @@ export default {
|
|||||||
const { origin, pathname } = new URL(parsedCurl.url.replace(/"/g, "").replace(/'/g, ""))
|
const { origin, pathname } = new URL(parsedCurl.url.replace(/"/g, "").replace(/'/g, ""))
|
||||||
this.url = origin
|
this.url = origin
|
||||||
this.path = pathname
|
this.path = pathname
|
||||||
|
this.uri = this.url + this.path
|
||||||
this.headers = []
|
this.headers = []
|
||||||
if (parsedCurl.headers) {
|
if (parsedCurl.headers) {
|
||||||
for (const key of Object.keys(parsedCurl.headers)) {
|
for (const key of Object.keys(parsedCurl.headers)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user