feat(shell): enhance regex validators to match on entire string (#1603)

This commit is contained in:
Lucas Fernandes Nogueira
2024-08-02 10:03:35 -03:00
committed by GitHub
parent b1e5cae5a0
commit 34df132fb1
8 changed files with 45 additions and 9 deletions
+8 -3
View File
@@ -88,9 +88,14 @@ impl ScopeObject for ScopeAllowedCommand {
crate::scope_entry::ShellAllowedArg::Fixed(fixed) => {
crate::scope::ScopeAllowedArg::Fixed(fixed)
}
crate::scope_entry::ShellAllowedArg::Var { validator } => {
let validator = Regex::new(&validator)
.unwrap_or_else(|e| panic!("invalid regex {validator}: {e}"));
crate::scope_entry::ShellAllowedArg::Var { validator, raw } => {
let regex = if raw {
validator
} else {
format!("^{validator}$")
};
let validator = Regex::new(&regex)
.unwrap_or_else(|e| panic!("invalid regex {regex}: {e}"));
crate::scope::ScopeAllowedArg::Var { validator }
}
});