Remove the leading . (CurrentDir) prefix while normalizing#159874
Open
schneems wants to merge 1 commit into
Open
Remove the leading . (CurrentDir) prefix while normalizing#159874schneems wants to merge 1 commit into
. (CurrentDir) prefix while normalizing#159874schneems wants to merge 1 commit into
Conversation
schneems
force-pushed
the
schneems/normalize-relative
branch
2 times, most recently
from
July 25, 2026 00:07
4613b4c to
0adbad0
Compare
Today, if you pass `./a/b` and `a/b` through normalize equality will tell you they are different. That was surprising to me. Here is how other languages behave with the current Rust behavior for comparison: | Implementation | `a` | `./a` | `a/` | `(empty)` | `.` | | --------------------------------- | --- | ----- | ---- | --------- | --------- | | Go `path.Clean` | `a` | `a` | `a` | `.` | `.` | | Java `Path.normalize` | `a` | `a` | `a` | `(empty)` | `(empty)` | | Node `path.posix.normalize` | `a` | `a` | `a/` | `.` | `.` | | C++ `lexically_normal` | `a` | `a` | `a/` | `(empty)` | `.` | | Ruby `Pathname#cleanpath` | `a` | `a` | `a` | `.` | `.` | | Python `os.path.normpath` | `a` | `a` | `a` | `.` | `.` | | Rust `normalize_lexically` (main) | `a` | `./a` | `a` | `(empty)` | `.` | Rust is the only one that keeps the leading `.`. This PR strips it so `./a` normalizes to `a` (a lone `.` is still preserved): | Implementation | `a` | `./a` | `a/` | `(empty)` | `.` | |---|---|---|---|---|---| | Rust `normalize_lexically` (proposed) | `a` | `a` | `a` | `(empty)` | `.` | This aligns the leading `.` case with other languages.
schneems
force-pushed
the
schneems/normalize-relative
branch
from
July 25, 2026 00:12
0adbad0 to
e8ebb2a
Compare
4 tasks
schneems
marked this pull request as ready for review
July 25, 2026 00:13
Collaborator
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
I'm going to wait for t-libs to weigh in on #159863, as I don't know what the intent of this API is. |
Member
|
One issue is that on Windows those can be different paths in special cases. For example: // This opens the console input
std::fs::File::open(r"CONIN$").unwrap();
// This attempts to open a file called `CONIN$`
std::fs::File::open(r"./CONIN$").unwrap(); |
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.
Today, if you pass
./a/banda/bthrough normalize equality will tell you they are different. That was surprising to me.Here is how other languages behave with the current Rust behavior for comparison:
a./aa/(empty).path.Cleanaaa..Path.normalizeaaa(empty)(empty)path.posix.normalizeaaa/..lexically_normalaaa/(empty).Pathname#cleanpathaaa..os.path.normpathaaa..normalize_lexically(main)a./aa(empty).Rust is the only one that keeps the leading
.. This PR strips it so./anormalizes toa(a lone.is still preserved):a./aa/(empty).normalize_lexically(proposed)aaa(empty).This aligns the leading
.case with other languages.Related tracking issue for
normalize_lexicallyunstable feature #134694.