mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-17 23:39:53 +02:00
Merge pull request #791 from Its-treason/feature/variable-name-validation
Enforce variable strictness & validation
This commit is contained in:
@@ -59,10 +59,24 @@ class Bru {
|
||||
throw new Error('Key is required');
|
||||
}
|
||||
|
||||
if (/^(?!\d)\w*$/.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.'
|
||||
);
|
||||
}
|
||||
|
||||
this.collectionVariables[key] = value;
|
||||
}
|
||||
|
||||
getVar(key) {
|
||||
if (/^(?!\d)\w*$/.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.'
|
||||
);
|
||||
}
|
||||
|
||||
return this.collectionVariables[key];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user