+
Skip to content
Merged
Show file tree
Hide file tree
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
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
13 changes: 13 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,16 @@ fn find_accessible() {
.stderr(predicate::str::is_empty())
.stdout(predicate::str::contains("abbbc").not());
}

#[test]
fn expression_empty_parentheses() {
Command::cargo_bin("find")
.expect("found binary")
.args(["-true", "(", ")"])
.assert()
.failure()
.stderr(predicate::str::contains(
"empty parentheses are not allowed",
))
.stdout(predicate::str::is_empty());
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载