find: warn on -name/-path patterns with a directory separator - #845
Open
MsfPablo wants to merge 1 commit into
Open
find: warn on -name/-path patterns with a directory separator#845MsfPablo wants to merge 1 commit into
MsfPablo wants to merge 1 commit into
Conversation
GNU find emits a warning when a -name/-iname pattern contains a '/' (it matches basenames only, so the pattern can never match and the user likely meant -wholename) and when a -path/-wholename pattern ends with '/' (a trailing separator can never match a real path). find now emits the same warnings on stderr while still exiting successfully. A pattern made up only of '/' (e.g. `-name /` or `-path /`) is exempt: '/' is a valid basename for the root entry, so warning would be a false alarm. GNU itself miscategorises this case (bug #62227); the existing find_slashes test encodes the correct behaviour and is preserved. Closes uutils#783
sylvestre
reviewed
Aug 19, 2026
| return Err(From::from(format!("missing argument to {}", args[i]))); | ||
| } | ||
| i += 1; | ||
| // GNU find warns when a -name/-iname pattern contains a directory |
Contributor
There was a problem hiding this comment.
does it really need a 6 lines comment ? please make it shorter
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #845 +/- ##
==========================================
+ Coverage 92.22% 92.28% +0.05%
==========================================
Files 35 35
Lines 7435 7452 +17
Branches 386 386
==========================================
+ Hits 6857 6877 +20
+ Misses 437 433 -4
- Partials 141 142 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Commit e00bd34 has test result changes: bfs testsuite: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #783.
GNU
findemits a warning when:-name/-inamepattern contains a/—-namematches basenames only, so such a pattern can never match and the user likely meant-wholename;-path/-ipath/-wholename/-iwholenamepattern ends with/— a trailing separator can never match a real path.This PR makes
findemit the same warnings on stderr while still exiting successfully.All-slash exemption: a pattern made up only of
/(e.g.-name /or-path /) is left alone —/is a valid basename for the root entry, so warning would be a false alarm. GNU itself miscategorises this case (GNU bug #62227); the existingfind_slashestest encodes the correct behaviour and continues to pass.Tests: four new regression tests in
tests/test_find.rscover the warning cases (name_pattern_with_separator_warns,path_pattern_ending_with_separator_warns), the no-warning positive case (name_pattern_without_separator_does_not_warn), and the all-slash exemption (all_slash_pattern_does_not_warn).cargo clippy -p findutils --tests -- -D warningsandcargo fmt --checkare clean; the fulltest_findsuite passes (73 passed, 0 failed).