fix(#964): Allow "." in variable names + make error message more consistent

This commit is contained in:
Nelu Platonov 2023-11-15 16:27:14 +01:00
parent f617504cd6
commit 2ee6c5effc
No known key found for this signature in database
GPG Key ID: DC1D6718097E5B33
4 changed files with 6 additions and 11 deletions

View File

@ -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(),

View File

@ -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;
}

View File

@ -1 +1 @@
export const envVariableNameRegex = /^(?!\d)[\w-]*$/;
export const envVariableNameRegex = /^(?!\d)[\w-.]*$/;

View File

@ -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.'
);
}