From 2ee6c5effcddc13bd9d82e61685e5a5a44ed6b02 Mon Sep 17 00:00:00 2001 From: Nelu Platonov Date: Wed, 15 Nov 2023 16:27:14 +0100 Subject: [PATCH 1/3] fix(#964): Allow "." in variable names + make error message more consistent --- .../EnvironmentDetails/EnvironmentVariables/index.js | 2 +- .../src/components/RequestPane/Vars/VarsTable/index.js | 7 +------ packages/bruno-app/src/utils/common/regex.js | 2 +- packages/bruno-js/src/bru.js | 6 +++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js index 9a8be4226..d2e47e578 100644 --- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js +++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentVariables/index.js @@ -26,7 +26,7 @@ const EnvironmentVariables = ({ environment, collection }) => { .required('Name cannot be empty') .matches( envVariableNameRegex, - 'Name contains invalid characters. Must only contain alphanumeric characters, "-" and "_"' + 'Name contains invalid characters. Must only contain alphanumeric characters, "-", "_", "." and cannot start with a digit.' ) .trim(), secret: Yup.boolean(), diff --git a/packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js b/packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js index 4f0177f75..dba6cf2a3 100644 --- a/packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js +++ b/packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js @@ -33,14 +33,9 @@ const VarsTable = ({ item, collection, vars, varType }) => { case 'name': { const value = e.target.value; - if (/^(?!\d).*$/.test(value) === false) { - toast.error('Variable names must not start with a number!'); - return; - } - if (envVariableNameRegex.test(value) === false) { toast.error( - 'Variable contains invalid character! Variables must only contain alpha-numeric characters, "-" and "_".' + 'Variable contains invalid characters! Variables must only contain alpha-numeric characters, "-", "_", "." and cannot start with a digit.' ); return; } diff --git a/packages/bruno-app/src/utils/common/regex.js b/packages/bruno-app/src/utils/common/regex.js index d55bb55b8..27838fa9f 100644 --- a/packages/bruno-app/src/utils/common/regex.js +++ b/packages/bruno-app/src/utils/common/regex.js @@ -1 +1 @@ -export const envVariableNameRegex = /^(?!\d)[\w-]*$/; +export const envVariableNameRegex = /^(?!\d)[\w-.]*$/; diff --git a/packages/bruno-js/src/bru.js b/packages/bruno-js/src/bru.js index 078aacc78..97260abc8 100644 --- a/packages/bruno-js/src/bru.js +++ b/packages/bruno-js/src/bru.js @@ -1,7 +1,7 @@ const Handlebars = require('handlebars'); const { cloneDeep } = require('lodash'); -const envVariableNameRegex = /^(?!\d)[\w-]*$/; +const envVariableNameRegex = /^(?!\d)[\w-.]*$/; class Bru { constructor(envVariables, collectionVariables, processEnvVars, collectionPath) { @@ -64,7 +64,7 @@ class Bru { if (envVariableNameRegex.test(key) === false) { throw new Error( `Variable name: "${key}" contains invalid characters!` + - ' Names must only contain alpha-numeric characters, "-", "_" and cannot start with a digit.' + ' Names must only contain alpha-numeric characters, "-", "_", "." and cannot start with a digit.' ); } @@ -75,7 +75,7 @@ class Bru { if (envVariableNameRegex.test(key) === false) { throw new Error( `Variable name: "${key}" contains invalid characters!` + - ' Names must only contain alpha-numeric characters and cannot start with a digit.' + ' Names must only contain alpha-numeric characters, "-", "_", "." and cannot start with a digit.' ); } From bad9d0a3ef642980941528ba5a57a89265e285a2 Mon Sep 17 00:00:00 2001 From: Nelu Platonov Date: Wed, 15 Nov 2023 20:29:40 +0100 Subject: [PATCH 2/3] fix(#964): Fix Handlebars interpolation when env var has "." in name --- packages/bruno-electron/src/ipc/network/interpolate-vars.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/network/interpolate-vars.js b/packages/bruno-electron/src/ipc/network/interpolate-vars.js index 6df6a7c1a..0c889ca79 100644 --- a/packages/bruno-electron/src/ipc/network/interpolate-vars.js +++ b/packages/bruno-electron/src/ipc/network/interpolate-vars.js @@ -43,7 +43,9 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces return str; } - const template = Handlebars.compile(str, { noEscape: true }); + // Handlebars doesn't allow dots as identifiers, so we need to use literal segments + let strLiteralSegment = str.replace('{{', '{{[').replace('}}', ']}}'); + const template = Handlebars.compile(strLiteralSegment, { noEscape: true }); // collectionVariables take precedence over envVars const combinedVars = { From 005a936a612760c7d177f96d8281a2ebdc9fb37b Mon Sep 17 00:00:00 2001 From: Nelu Platonov Date: Wed, 15 Nov 2023 21:42:38 +0100 Subject: [PATCH 3/3] fix(#964): Use const --- packages/bruno-electron/src/ipc/network/interpolate-vars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/network/interpolate-vars.js b/packages/bruno-electron/src/ipc/network/interpolate-vars.js index 0c889ca79..4a709f5ae 100644 --- a/packages/bruno-electron/src/ipc/network/interpolate-vars.js +++ b/packages/bruno-electron/src/ipc/network/interpolate-vars.js @@ -44,7 +44,7 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces } // Handlebars doesn't allow dots as identifiers, so we need to use literal segments - let strLiteralSegment = str.replace('{{', '{{[').replace('}}', ']}}'); + const strLiteralSegment = str.replace('{{', '{{[').replace('}}', ']}}'); const template = Handlebars.compile(strLiteralSegment, { noEscape: true }); // collectionVariables take precedence over envVars