fix: can't import curl command with data-urlencode (#3905)
Co-authored-by: Anwarul Islam <anwaarulislaam@gmail.com> Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
@@ -868,6 +868,38 @@ const samples = [
|
|||||||
requestVariables: [],
|
requestVariables: [],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
command: `curl --location 'https://api.example.net/id/1164/requests' \
|
||||||
|
--header 'Accept: application/vnd.test-data.v2.1+json' \
|
||||||
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
--data-urlencode 'data={"type":"test","typeId":"101"}' \
|
||||||
|
--data-urlencode 'data2={"type":"test2","typeId":"123"}'`,
|
||||||
|
response: makeRESTRequest({
|
||||||
|
method: "POST",
|
||||||
|
name: "Untitled",
|
||||||
|
endpoint: "https://api.example.net/id/1164/requests",
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: true,
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
contentType: "application/x-www-form-urlencoded",
|
||||||
|
body: `data: {"type":"test","typeId":"101"}
|
||||||
|
data2: {"type":"test2","typeId":"123"}`,
|
||||||
|
},
|
||||||
|
params: [],
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
active: true,
|
||||||
|
key: "Accept",
|
||||||
|
value: "application/vnd.test-data.v2.1+json",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
preRequestScript: "",
|
||||||
|
testScript: "",
|
||||||
|
requestVariables: [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
describe("Parse curl command to Hopp REST Request", () => {
|
describe("Parse curl command to Hopp REST Request", () => {
|
||||||
|
|||||||
@@ -33,7 +33,27 @@ export const parseCurlCommand = (curlCommand: string) => {
|
|||||||
// const compressed = !!parsedArguments.compressed
|
// const compressed = !!parsedArguments.compressed
|
||||||
|
|
||||||
curlCommand = preProcessCurlCommand(curlCommand)
|
curlCommand = preProcessCurlCommand(curlCommand)
|
||||||
const parsedArguments = parser(curlCommand)
|
|
||||||
|
const args: parser.Arguments = parser(curlCommand)
|
||||||
|
|
||||||
|
const parsedArguments = pipe(
|
||||||
|
args,
|
||||||
|
O.fromPredicate(
|
||||||
|
(args) =>
|
||||||
|
objHasProperty("dataUrlencode", "string")(args) ||
|
||||||
|
objHasProperty("dataUrlencode", "object")(args)
|
||||||
|
),
|
||||||
|
O.map((args) => {
|
||||||
|
const urlEncodedData: string[] = Array.isArray(args.dataUrlencode)
|
||||||
|
? args.dataUrlencode
|
||||||
|
: [args.dataUrlencode]
|
||||||
|
|
||||||
|
const data = A.map(decodeURIComponent)(urlEncodedData)
|
||||||
|
|
||||||
|
return { ...args, d: data }
|
||||||
|
}),
|
||||||
|
O.getOrElse(() => args)
|
||||||
|
)
|
||||||
|
|
||||||
const headerObject = getHeaders(parsedArguments)
|
const headerObject = getHeaders(parsedArguments)
|
||||||
const { headers } = headerObject
|
const { headers } = headerObject
|
||||||
|
|||||||
Reference in New Issue
Block a user