Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions relay-cabi/src/codeowners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ fn translate_codeowners_pattern(pattern: &str) -> Option<Regex> {
let trailing_slash = pattern_vec.get(i + 2) == Some(&'/');

if (left_anchored || leading_slash) && (right_anchored || trailing_slash) {
regex += ".*";
num_to_skip = Some(2);
// Allows the trailing slash after ** to be optional
if trailing_slash {
regex += "/?";
// **/ matches zero or more complete path segments
regex += "(?:.*/)?";
num_to_skip = Some(3);
} else {
// ** at end matches anything
regex += ".*";
num_to_skip = Some(2);
}
continue;
}
Expand Down Expand Up @@ -209,5 +211,14 @@ mod tests {
assert!(regex.is_match(b"/docs/subdir/file.css"));
assert!(regex.is_match(b"file.css"));
assert!(!regex.is_match(b"/docs/file.txt"));

// /**/<filename> should match <filename> exactly anywhere it appears
let pattern = "/**/foo.py";
let regex = translate_codeowners_pattern(pattern).unwrap();
assert!(regex.is_match(b"foo.py"));
assert!(regex.is_match(b"dir/foo.py"));
assert!(regex.is_match(b"dir/subdir/foo.py"));
assert!(!regex.is_match(b"not_foo.py"));
assert!(!regex.is_match(b"dir/not_foo.py"));
}
}
Loading