mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-08 14:02:09 +01:00
Merge pull request #971 from nelup20/bugfix/964-env_var_dot_validation
fix(#964): Allow "." in variable names + make error message more consistent
This commit is contained in:
commit
2aa876e526
@ -26,7 +26,7 @@ const EnvironmentVariables = ({ environment, collection }) => {
|
|||||||
.required('Name cannot be empty')
|
.required('Name cannot be empty')
|
||||||
.matches(
|
.matches(
|
||||||
envVariableNameRegex,
|
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(),
|
.trim(),
|
||||||
secret: Yup.boolean(),
|
secret: Yup.boolean(),
|
||||||
|
@ -33,14 +33,9 @@ const VarsTable = ({ item, collection, vars, varType }) => {
|
|||||||
case 'name': {
|
case 'name': {
|
||||||
const value = e.target.value;
|
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) {
|
if (envVariableNameRegex.test(value) === false) {
|
||||||
toast.error(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
export const envVariableNameRegex = /^(?!\d)[\w-]*$/;
|
export const envVariableNameRegex = /^(?!\d)[\w-.]*$/;
|
||||||
|
@ -43,7 +43,9 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const template = Handlebars.compile(str, { noEscape: true });
|
// Handlebars doesn't allow dots as identifiers, so we need to use literal segments
|
||||||
|
const strLiteralSegment = str.replace('{{', '{{[').replace('}}', ']}}');
|
||||||
|
const template = Handlebars.compile(strLiteralSegment, { noEscape: true });
|
||||||
|
|
||||||
// collectionVariables take precedence over envVars
|
// collectionVariables take precedence over envVars
|
||||||
const combinedVars = {
|
const combinedVars = {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const { cloneDeep } = require('lodash');
|
const { cloneDeep } = require('lodash');
|
||||||
|
|
||||||
const envVariableNameRegex = /^(?!\d)[\w-]*$/;
|
const envVariableNameRegex = /^(?!\d)[\w-.]*$/;
|
||||||
|
|
||||||
class Bru {
|
class Bru {
|
||||||
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
||||||
@ -64,7 +64,7 @@ class Bru {
|
|||||||
if (envVariableNameRegex.test(key) === false) {
|
if (envVariableNameRegex.test(key) === false) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Variable name: "${key}" contains invalid characters!` +
|
`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) {
|
if (envVariableNameRegex.test(key) === false) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Variable name: "${key}" contains invalid characters!` +
|
`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.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user