From d45f15e9cb55db04204fa12a4a438b6a8a0e7f1a Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Mon, 24 Jun 2024 12:16:50 +0600 Subject: [PATCH] fix: prevent unwanted variable wrapping during Insomnia import (#4076) feat: conditionally check path variable --- .../src/helpers/import-export/import/insomnia.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts b/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts index a69dbb9c3..a3781ad53 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts @@ -48,8 +48,13 @@ const parseInsomniaDoc = (content: string) => const replacePathVarTemplating = (expression: string) => expression.replaceAll(/:([^/]+)/g, "<<$1>>") -const replaceVarTemplating = (expression: string) => - pipe(expression, replacePathVarTemplating, replaceInsomniaTemplating) +const replaceVarTemplating = (expression: string, pathVar = false) => { + return pipe( + expression, + pathVar ? replacePathVarTemplating : (x) => x, + replaceInsomniaTemplating + ) +} const getFoldersIn = ( folder: InsomniaFolderResource | null, @@ -208,7 +213,7 @@ const getHoppRequest = (req: InsomniaRequestResource): HoppRESTRequest => makeRESTRequest({ name: req.name ?? "Untitled Request", method: req.method?.toUpperCase() ?? "GET", - endpoint: replaceVarTemplating(req.url ?? ""), + endpoint: replaceVarTemplating(req.url ?? "", true), auth: getHoppReqAuth(req), body: getHoppReqBody(req), headers: getHoppReqHeaders(req),