Merge pull request #791 from Its-treason/feature/variable-name-validation

Enforce variable strictness & validation
This commit is contained in:
Anoop M D
2023-10-26 22:19:57 +05:30
committed by GitHub
7 changed files with 143 additions and 188 deletions

View File

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