mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-09 23:28:51 +02:00
Merge pull request #866 from Its-treason/bugfix/variable-name-validation
fix(#853): Allow - in variable names & small refactor
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
const Handlebars = require('handlebars');
|
||||
const { cloneDeep } = require('lodash');
|
||||
|
||||
const envVariableNameRegex = /^(?!\d)[\w-]*$/;
|
||||
|
||||
class Bru {
|
||||
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
||||
this.envVariables = envVariables;
|
||||
@ -59,10 +61,10 @@ class Bru {
|
||||
throw new Error('Key is required');
|
||||
}
|
||||
|
||||
if (/^(?!\d)\w*$/.test(key) === false) {
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
@ -70,7 +72,7 @@ class Bru {
|
||||
}
|
||||
|
||||
getVar(key) {
|
||||
if (/^(?!\d)\w*$/.test(key) === false) {
|
||||
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.'
|
||||
|
Reference in New Issue
Block a user