Stop collapsing three-character drive-relative paths to the drive root - #2143
Merged
martindurant merged 1 commit intoSep 14, 2026
Merged
Conversation
make_path_posix treated any Windows path of length 3 or less with a colon in second place as a drive root. That covers "c:", "c:/" and "c:\", but also "c:x", which names "x" relative to drive c. Those paths came back as "c:/", silently pointing at a different, real location and dropping the name, while a longer drive-relative path such as "c:xy" is returned unchanged. Only treat "X:" and "X:" followed by a separator as the root, so a short drive-relative path is handled like a longer one. Making drive-relative paths absolute stays out of scope; test_local already marks that case as unsupported. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
On Windows,
make_path_posixturns a three-character drive-relative path into the drive root, dropping the name:C:xnamesxrelative to the current directory on drive C (ntpath.abspath("C:x")resolves it that way). ReturningC:/is worse than leaving the path alone: it looks absolute and valid, so a call likefs.rm("C:x")orfs.ls("D:a")quietly operates on the drive root instead of failing or using the intended path.Cause
The length check is meant for the roots
c:,c:/andc:\, but any three-character path with a colon in second place matches, includingc:x,D:aande:..Change
Only treat
X:andX:followed by/or\as the root. A three-character drive-relative path now falls through to the same handling as a longer one, soC:xbehaves likeC:xy.This deliberately does not make drive-relative paths absolute.
test_make_path_posix_returns_absolute_pathsalready marks"f:foo"asxfail(WIN, reason="unsupported"), and this change leaves that case as it was. It only removes the silent redirect to the root.Tests
test_make_path_posix_short_drive_relative_path_is_not_the_root, Windows-only, forc:x,D:aande:.. All three fail againstmasterand pass with the change.test_local.py: 160 passed, 4 skipped, 8 xfailed — the existing root cases (C:\,e:) still resolve to the root, and thef:fooxfail is unchanged, with no unexpected passes.ruff0.14.3 (the pre-commit pin),ruff formatandcodespellare clean.🤖 Generated with Claude Code