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

This commit is contained in:
Lucas Fernandes Nogueira authored and GitHub committed 2024-08-02 10:03:35 -03:00
1 parent b1e5cae5a0
commit 34df132fb1
8 files changed
+45 -9

No files matched your search

+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 }
}
});