summaryrefslogtreecommitdiff
path: root/bindgen/regex_set.rs
diff options
context:
space:
mode:
authorAdam Gausmann <adam@gaussian.dev>2022-10-24 10:39:52 -0500
committerGitHub <noreply@github.com>2022-10-24 10:39:52 -0500
commit6086694d40f8df09db79bc9a7b7eec29131f424a (patch)
treee403d255053bb1e61a34f19dda1f878f888511cf /bindgen/regex_set.rs
parent170b79c88ea5d527184eccc2903ae4ac52272800 (diff)
Sanitize RegexSet input so alternation is properly handled (#1756)
* tests: Avoid using globs as regexes * Sanitize regex set input to properly handle alternation * Add test case for alternates/anchors interaction * emit warning if wildcard pattern is used * update changelog and bump versions Co-authored-by: Darren Kulp <darren@kulp.ch> Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
Diffstat (limited to 'bindgen/regex_set.rs')
-rw-r--r--bindgen/regex_set.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs
index 9262c4ee..9f1e2251 100644
--- a/bindgen/regex_set.rs
+++ b/bindgen/regex_set.rs
@@ -26,7 +26,11 @@ impl RegexSet {
where
S: AsRef<str>,
{
- self.items.push(string.as_ref().to_owned());
+ let string = string.as_ref().to_owned();
+ if string == "*" {
+ warn!("using wildcard patterns (`*`) is no longer considered valid. Use `.*` instead");
+ }
+ self.items.push(string);
self.matched.push(Cell::new(false));
self.set = None;
}
@@ -53,7 +57,7 @@ impl RegexSet {
/// Must be called before calling `matches()`, or it will always return
/// false.
pub fn build(&mut self, record_matches: bool) {
- let items = self.items.iter().map(|item| format!("^{}$", item));
+ let items = self.items.iter().map(|item| format!("^({})$", item));
self.record_matches = record_matches;
self.set = match RxSet::new(items) {
Ok(x) => Some(x),