Skip to content

Commit

Permalink
Check for expression that contain only empty parentheses.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbings committed Apr 11, 2024
1 parent d8e2ce2 commit 7c92c4d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ fn build_matcher_tree(
if !expecting_bracket {
return Err(From::from("you have too many ')'"));
}

let bracket = args[i - 1];
if bracket == "(" {
return Err(From::from(
"invalid expression; empty parentheses are not allowed.",
));
}

return Ok((i, top_level_matcher.build()));
}
"-d" | "-depth" => {
Expand Down Expand Up @@ -941,7 +949,10 @@ mod tests {
fn build_top_level_matcher_too_many_brackets() {
let mut config = Config::default();

if let Err(e) = build_top_level_matcher(&["-true", "(", ")", ")"], &mut config) {
if let Err(e) = build_top_level_matcher(
&["-type", "f", "(", "-name", "*.txt", ")", ")"],
&mut config,
) {
assert!(e.to_string().contains("too many ')'"));
} else {
panic!("parsing argument list with too many closing brackets should fail");
Expand Down Expand Up @@ -997,6 +1008,17 @@ mod tests {
}
}

#[test]
fn build_top_level_matcher_expression_empty_parentheses() {
let mut config = Config::default();

if let Err(e) = build_top_level_matcher(&["-true", "(", ")"], &mut config) {
assert!(e.to_string().contains("empty parentheses are not allowed"));
} else {
panic!("parsing argument list with empty parentheses in an expression should fail");
}
}

#[test]
fn comparable_value_matches() {
assert!(
Expand Down

0 comments on commit 7c92c4d

Please sign in to comment.