-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix dirname handling of paths ending in /.
#8911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
b9a43db to
c78014a
Compare
Fixes uutils#8910 Match POSIX/GNU behavior where dirname("/home/dos/.") returns "/home/dos" instead of "/home". This aligns with the basename fix from uutils#8373 (c5268a8). The issue occurs because Rust's Path::parent() normalizes paths, treating "/home/dos/." the same as "/home/dos/", both returning "/home" as the parent. This breaks tools like homeshick that rely on correct dirname behavior for symlink generation. Solution: - Detect paths ending in "/." using byte-level checking - Strip the "/." suffix manually before path operations - Handle edge case: "/." -> "/" - Preserve non-UTF-8 path handling with platform-specific code - Add comprehensive tests covering edge cases Tests added: - Basic "/." handling (5 test cases) - Flag interaction with -z/--zero - Multiple paths with mixed "/." suffixes - Edge cases: double slashes, dots in middle - Unicode/emoji paths - Non-UTF-8 paths (Unix only) - Backward compatibility verification (7 test cases)
c78014a to
df6ef34
Compare
Previously, when encountering invalid UTF-8 on non-Unix platforms for paths ending in /., the code would incorrectly print the original path unchanged instead of falling through to normal dirname logic. This fix restructures the code to track whether the /. suffix was successfully handled, and falls through to Path::parent() logic when it cannot be handled (either because the path doesnt end with /. or because UTF-8 conversion failed on non-Unix).
|
GNU testsuite comparison: |
cakebaker
reviewed
Oct 15, 2025
cakebaker
reviewed
Oct 15, 2025
cakebaker
reviewed
Oct 15, 2025
- Remove duplicate test case for /usr/local/bin/. in test_trailing_dot - Consolidate test_existing_behavior_preserved by removing redundant tests - Extract trailing dot handling into dedicated handle_trailing_dot function - Eliminates handled_trailing_dot boolean for cleaner code flow Addresses feedback from cakebaker on PR uutils#8911
|
GNU testsuite comparison: |
Wrap POSIX and GNU documentation URLs in angle brackets to comply with rustdoc requirements (-D rustdoc::bare-urls)
|
GNU testsuite comparison: |
naoNao89
added a commit
to naoNao89/coreutils
that referenced
this pull request
Oct 25, 2025
Fix dirname handling of paths ending in `/.`
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.
fixes #8910
The problem is that dirname("/home/dos/.") was giving "/home" when it should return "/home/dos". This broke homeshick for the reporter because their symlinks ended up pointing to the wrong places.
Turns out Rust's Path::parent() normalizes the path automatically, so it treats "/home/dos/." the same as "/home/dos/" - both just return "/home". Not what we want for POSIX compliance.
The fix is pretty straightforward: check if the path ends with "/." before calling parent(), and if it does, just strip those two characters off and return what's left. Special case for "/." which becomes "/".
I followed the same pattern basename used when they hit this exact #8373. Used byte-level checking so non-UTF-8 paths still work fine.
Added a bunch of tests covering the basic case, edge cases like double slashes, emoji paths, and made sure nothing broke for existing behavior.