From 2ee6c5effcddc13bd9d82e61685e5a5a44ed6b02 Mon Sep 17 00:00:00 2001 From: Nelu Platonov Date: Wed, 15 Nov 2023 16:27:14 +0100 Subject: [PATCH] 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 9a8be422..d2e47e57 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 4f0177f7..dba6cf2a 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 d55bb55b..27838fa9 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 078aacc7..97260abc 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.' ); }