fix: show path-separator error for any pattern containing a separator#1973
fix: show path-separator error for any pattern containing a separator#1973SAY-5 wants to merge 2 commits intosharkdp:masterfrom
Conversation
Fixes sharkdp#1873. `ensure_search_pattern_is_not_a_path` previously only fired when the pattern both (a) contained a path-separation character AND (b) happened to match an existing directory on disk. That meant users who typed a pattern with a slash got the helpful error only by coincidence — any pattern with a separator that didnt also happen to be a real directory returned zero results silently. The separator check alone is sufficient: fd's default search is file-name based, so any pattern containing a separator will never match. Remove the extra `Path::new(&opts.pattern).is_dir()` condition so the error is consistent for every pattern with a separator. No test change needed; the existing error text still makes sense for non-directory patterns (the advice to use `fd . 'pattern'` or `fd --full-path 'pattern'` is the same either way). Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
MAIN_SEPARATOR is '\\' on Windows, which is also a regex escape character. Treating '\\' as a path-separator produced false positives for valid regex patterns such as '\\Ac', '\\d+', etc., breaking the test_smart_case integration test on windows-2025. Restrict the check to '/', which is always a path separator (including on Windows) and has no regex meaning. This still fixes sharkdp#1873 on all platforms without breaking regex patterns on Windows. Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
|
Pushed a follow-up (8c9f814) that restricts the path-separator check to '/'. The CI failure on windows-*-msvc / windows-gnu was caused by me using |
|
Hi @tmccombs — I noticed this was closed without comment. Was the approach wrong, or is there something I can adjust? Happy to rework if you'd prefer a different approach to fixing #1873. Apologies if the initial breaking of Windows CI caused frustration — the follow-up (8c9f814) limits the check to '/' only, which sidesteps the regex-escape collision entirely. |
|
There have been many PRs created for this already that do basically the same thing, and from the style of the comments, I'm suspicious this is AI generated. |
|
I am doing it manually, sorry if it felt that way @tmccombs |
|
Understood, @tmccombs — thanks for the context on the existing PRs. I'll leave it at that. Appreciate you looking. |
|
If you want to make this mergeable, the issues with it are:
|
|
Hi @tmccombs — followed up on your three points. Force-pushed onto the same branch:
Would appreciate a reopen so CI can run on the updated commit. Happy to further adjust the Windows check (e.g. also include forward-slash-free but backslash-and-path patterns) if you'd prefer different coverage there. |
|
Thanks you. Looks like I can't reopen because there was a force push, but if you open a new PR, I can look at it. Sorry. |
Fixes #1873.
Problem
`fd pattern` with a path-separator character in the pattern silently returns zero results most of the time. The user only sees the helpful "pattern contains a path-separation character" error when the pattern also happens to match an existing directory on disk:
That's because `ensure_search_pattern_is_not_a_path` in `src/main.rs` checks both:
Fix
Drop the `is_dir()` check. By fd's design, the search is file-name based unless `--full-path` is set, so a pattern containing a separator will never match anything. The error should always fire.
The existing error message already generalizes: it suggests `fd . 'pattern'` or `fd --full-path 'pattern'`, both of which make sense whether the pattern is a real directory or not.
Behavior change
Before: silent zero results for patterns with separators unless the pattern happens to be a real directory.
After: consistent helpful error for any such pattern, pointing the user to `--full-path` or a corrected match-all invocation.
This is the change the issue author explicitly asked for ("I would expect the error about how a pattern with a '/' in it will not lead to any search results to be displayed regardless of the pattern possibly being a directory path").