fix: curl parser x-www-form-urlencoded body parsing (#2528)

This commit is contained in:
kyteinsky
2022-07-28 21:03:05 +05:30
committed by GitHub
parent e9576dd339
commit fa0e7f4785
2 changed files with 33 additions and 1 deletions

View File

@@ -809,6 +809,37 @@ const samples = [
testScript: "",
}),
},
{
command: `curl https://example.com -d "alpha=beta&request_id=4"`,
response: makeRESTRequest({
method: "POST",
name: "Untitled request",
endpoint: "https://example.com/",
auth: {
authType: "none",
authActive: true,
},
body: {
contentType: "application/x-www-form-urlencoded",
body: rawKeyValueEntriesToString([
{
active: true,
key: "alpha",
value: "beta",
},
{
active: true,
key: "request_id",
value: "4",
},
]),
},
params: [],
headers: [],
preRequestScript: "",
testScript: "",
}),
},
]
describe("Parse curl command to Hopp REST Request", () => {

View File

@@ -93,7 +93,8 @@ export const parseCurlCommand = (curlCommand: string) => {
hasBodyBeenParsed = true
} else if (
rawContentType.includes("application/x-www-form-urlencoded") &&
!!pairs
!!pairs &&
Array.isArray(rawData)
) {
body = pairs.map((p) => p.join(": ")).join("\n") || null
contentType = "application/x-www-form-urlencoded"