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
4 changes: 3 additions & 1 deletion src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ fn convert_arg_to_number(
option_name: &str,
value_as_string: &str,
) -> Result<usize, Box<dyn Error>> {
// Only accept plain decimal digits. Rust's `usize::from_str` also accepts a
// leading '+', but GNU find rejects a signed value like "+1" here.
match value_as_string.parse::<usize>() {
Ok(val) => Ok(val),
Ok(val) if value_as_string.bytes().all(|b| b.is_ascii_digit()) => Ok(val),
_ => Err(From::from(format!(
"Expected a positive decimal integer argument to {option_name}, but got \
`{value_as_string}'"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ fn size_rejects_non_numeric_prefix() {
}
}

#[test]
fn depth_rejects_signed_value() {
// A signed depth like "+1" is rejected, matching GNU find.
for opt in ["-maxdepth", "-mindepth"] {
ucmd()
.args(&["./test_data", opt, "+1"])
.fails()
.stderr_contains("positive decimal integer argument");
ucmd().args(&["./test_data", opt, "1"]).succeeds();
}
}

#[test]
fn multiple_matcher_failure() {
ucmd()
Expand Down
Loading