chore: replace regex with regex-lite, where appropriate (#1200)
As explained on https://crates.io/crates/regex-lite, `regex-lite` is a lighter alternative to `regex` and seems to be sufficient for our purposes.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use multimap::MultiMap;
|
||||
use regex::Error as RegexError;
|
||||
use regex::Regex;
|
||||
use regex_lite::Error as RegexError;
|
||||
use regex_lite::Regex;
|
||||
|
||||
use crate::ExecCall;
|
||||
use crate::Forbidden;
|
||||
@@ -29,7 +29,7 @@ impl Policy {
|
||||
} else {
|
||||
let escaped_substrings = forbidden_substrings
|
||||
.iter()
|
||||
.map(|s| regex::escape(s))
|
||||
.map(|s| regex_lite::escape(s))
|
||||
.collect::<Vec<_>>()
|
||||
.join("|");
|
||||
Some(Regex::new(&format!("({escaped_substrings})"))?)
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::arg_matcher::ArgMatcher;
|
||||
use crate::opt::OptMeta;
|
||||
use log::info;
|
||||
use multimap::MultiMap;
|
||||
use regex::Regex;
|
||||
use regex_lite::Regex;
|
||||
use starlark::any::ProvidesStaticType;
|
||||
use starlark::environment::GlobalsBuilder;
|
||||
use starlark::environment::LibraryExtension;
|
||||
@@ -73,7 +73,7 @@ impl PolicyParser {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ForbiddenProgramRegex {
|
||||
pub regex: regex::Regex,
|
||||
pub regex: regex_lite::Regex,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl PolicyBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fn build(self) -> Result<Policy, regex::Error> {
|
||||
fn build(self) -> Result<Policy, regex_lite::Error> {
|
||||
let programs = self.programs.into_inner();
|
||||
let forbidden_program_regexes = self.forbidden_program_regexes.into_inner();
|
||||
let forbidden_substrings = self.forbidden_substrings.into_inner();
|
||||
@@ -207,7 +207,7 @@ fn policy_builtins(builder: &mut GlobalsBuilder) {
|
||||
.unwrap()
|
||||
.downcast_ref::<PolicyBuilder>()
|
||||
.unwrap();
|
||||
let compiled_regex = regex::Regex::new(®ex)?;
|
||||
let compiled_regex = regex_lite::Regex::new(®ex)?;
|
||||
policy_builder.add_forbidden_program_regex(compiled_regex, reason);
|
||||
Ok(NoneType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user