feat(#682): Add validation for request vars & dynamic vars

This commit is contained in:
Its-treason
2023-10-25 23:13:37 +02:00
parent 3a5a213242
commit 827df18c62
4 changed files with 30 additions and 33 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];
}
}