Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Fully escape allowlist rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ranweiler committed Jan 27, 2023
1 parent 6829318 commit 01175a2
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/agent/coverage/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,10 @@ impl AllowListLine {

#[allow(clippy::single_char_pattern)]
fn glob_to_regex(expr: &str) -> Result<Regex> {
// Treat `.` as literal, not match-any.
//
// Use character class syntax to avoid double-escaping.
let expr = expr.replace(".", r"[.]");
let expr = regex::escape(expr);

// Don't make users escape Windows path separators.
let expr = expr.replace(r"\", r"\\");

// Translate glob wildcards into quantified regexes.
let expr = expr.replace("*", ".*");
// Translate escaped glob wildcards into quantified regexes.
let expr = expr.replace(r"\*", ".*");

// Anchor to line start and end.
let expr = format!("^{expr}$");
Expand Down

0 comments on commit 01175a2

Please sign in to comment.