From 3bf3d30ce85ad89911cbad1c14a4ddad8535ed5f Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 23 Oct 2022 19:48:02 +0530 Subject: [PATCH] fix: environment var interpolation issues --- packages/bruno-app/package.json | 1 + .../bruno-app/src/utils/collections/index.js | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index 9b300bd3..01f7c8c9 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -40,6 +40,7 @@ "react-hot-toast": "^2.4.0", "react-redux": "^7.2.6", "react-tabs": "^3.2.3", + "reckonjs": "^0.1.2", "sass": "^1.46.0", "split-on-first": "^3.0.0", "styled-components": "^5.3.3", diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index cb3cade4..bfa84a1c 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -1,4 +1,4 @@ -import template from 'lodash/template'; +import reckon from 'reckonjs'; import get from 'lodash/get'; import each from 'lodash/each'; import find from 'lodash/find'; @@ -356,21 +356,26 @@ export const isLocalCollection = (collection) => { }; export const interpolateEnvironmentVars = (item, variables) => { - const envVars = {}; - const { request } = item; + const envVars = { + interpolation: { escapeValue: true } + }; + const _item = item.draft ? item.draft : item; + const { request } = _item; each(variables, (variable) => { envVars[variable.name] = variable.value; }); - const templateOpts = { - interpolate: /{{([\s\S]+?)}}/g, //interpolate content using markers `{{}}` - evaluate: null, // prevent any js evaluation - escape: null // disable any escaping + // TODO: Find a better interpolation library + const interpolate = (str) => { + if(!str || !str.length || typeof str !== "string") { + return str; + } + + return str.reckon(envVars); }; - const interpolate = (str) => template(str, templateOpts)(envVars); - request.url = interpolate(request.url); + console.log(request.url); each(request.headers, (header) => { header.value = interpolate(header.value);