Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: can't import curl command with data-urlencode (#3905)
Dmitry1113c79e202f
diff --git a/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js b/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.jsindex 896fbeb08..2ea2cd039 100644--- a/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js+++ b/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js@@ -868,6 +868,38 @@ const samples = [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", () => {diff --git a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts b/packages/hoppscotch-common/src/helpers/curl/curlparser.tsindex 638680c5b..40bba10ba 100644--- a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts+++ b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts@@ -33,7 +33,27 @@ export const parseCurlCommand = (curlCommand: string) => {// const compressed = !!parsedArguments.compressedcurlCommand = 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 { headers } = headerObject