From bb36d3235914b854cfb70df61aa9a355cca4f839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9fany=20Larissa?= <86860471+stelardn@users.noreply.github.com> Date: Wed, 19 Feb 2025 04:48:02 -0300 Subject: [PATCH] fix: cURL header imports without trailing space (#4724) --- .../helpers/curl/__tests__/curlparser.spec.js | 42 +++++++++++++++++++ .../src/helpers/curl/sub_helpers/headers.ts | 1 + 2 files changed, 43 insertions(+) diff --git a/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js b/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js index 4b12a5d5..91d9b4d8 100644 --- a/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js +++ b/packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js @@ -958,6 +958,48 @@ data2: {"type":"test2","typeId":"123"}`, responses: {}, }), }, + { + command: `curl --request GET \ + --url https://echo.hoppscotch.io/ \ + --header 'Authorization:Basic YXNkZmdoOjEyMzQ=' \ + --header 'User-Agent:Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0' + --header 'foo:bar'`, + response: makeRESTRequest({ + method: "GET", + name: "Untitled", + endpoint: "https://echo.hoppscotch.io/", + auth: { + authType: "basic", + authActive: true, + username: "asdfgh", + password: "1234", + }, + body: { + contentType: null, + body: null, + }, + params: [], + headers: [ + { + active: true, + key: "User-Agent", + value: + "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0", + description: "", + }, + { + active: true, + key: "foo", + value: "bar", + description: "", + }, + ], + preRequestScript: "", + testScript: "", + requestVariables: [], + responses: {}, + }), + }, ] describe("Parse curl command to Hopp REST Request", () => { diff --git a/packages/hoppscotch-common/src/helpers/curl/sub_helpers/headers.ts b/packages/hoppscotch-common/src/helpers/curl/sub_helpers/headers.ts index 5135729a..fb839cc0 100644 --- a/packages/hoppscotch-common/src/helpers/curl/sub_helpers/headers.ts +++ b/packages/hoppscotch-common/src/helpers/curl/sub_helpers/headers.ts @@ -11,6 +11,7 @@ import { import { tupleToRecord } from "~/helpers/functional/record" const getHeaderPair = flow( + S.replace(":", ": "), S.split(": "), // must have a key and a value O.fromPredicate((arr) => arr.length === 2),