diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index 78c7af42..db3e9d49 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -220,7 +220,7 @@ fn convert_arg_to_comparable_value( option_name: &str, value_as_string: &str, ) -> Result> { - let re = Regex::new(r"([+-]?)(\d+)$")?; + let re = Regex::new(r"^([+-]?)(\d+)$")?; if let Some(groups) = re.captures(value_as_string) { if let Ok(val) = groups[2].parse::() { return Ok(match &groups[1] { @@ -1260,6 +1260,20 @@ mod tests { } } + #[test] + fn convert_exception_arg_to_comparable_value_test() { + let exception_args = ["1%2", "1%2%3", "1a2", "1%2a", "abc", "-", "+", "%"]; + + for arg in exception_args { + let comparable = convert_arg_to_comparable_value("test", arg); + assert!( + comparable.is_err(), + "{} should be parse to Comparable correctly", + arg + ); + } + } + #[test] fn parse_date_str_to_timestamps_test() { let full_date_timestamps = parse_date_str_to_timestamps("jan 01, 2025 00:00:01").unwrap(); diff --git a/tests/find_cmd_tests.rs b/tests/find_cmd_tests.rs index e7755541..c6106c87 100644 --- a/tests/find_cmd_tests.rs +++ b/tests/find_cmd_tests.rs @@ -506,6 +506,32 @@ fn find_accessible() { .stdout(predicate::str::contains("abbbc").not()); } +#[test] +fn find_time() { + let args = ["1", "+1", "-1"]; + let exception_args = ["1%2", "1%2%3", "1a2", "1%2a", "abc", "-", "+", "%"]; + + ["-ctime", "-atime", "-mtime"].iter().for_each(|flag| { + args.iter().for_each(|arg| { + Command::cargo_bin("find") + .expect("found binary") + .args([".", flag, arg]) + .assert() + .success() + .stderr(predicate::str::is_empty()); + }); + + exception_args.iter().for_each(|arg| { + Command::cargo_bin("find") + .expect("found binary") + .args([".", flag, arg]) + .assert() + .failure() + .stdout(predicate::str::is_empty()); + }); + }); +} + #[test] fn expression_empty_parentheses() { Command::cargo_bin("find")