-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-78079: Fix UNC device path root normalization in pathlib #102003
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
Changes from all commits
99f62bc
6651b67
87519ba
c444a3c
36623c0
aea236e
bb0af91
f412f87
8ff07fc
723a5aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,9 +322,14 @@ def _parse_path(cls, path): | |
if altsep: | ||
path = path.replace(altsep, sep) | ||
drv, root, rel = cls._flavour.splitroot(path) | ||
if drv.startswith(sep): | ||
# pathlib assumes that UNC paths always have a root. | ||
root = sep | ||
if not root and drv.startswith(sep) and not drv.endswith(sep): | ||
drv_parts = drv.split(sep) | ||
if len(drv_parts) == 4 and drv_parts[2] not in '?.': | ||
# e.g. //server/share | ||
root = sep | ||
elif len(drv_parts) == 6: | ||
# e.g. //?/unc/server/share | ||
root = sep | ||
parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa, we Don't we already know that Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The interning of the path parts is longstanding pathlib behaviour. Honestly I don't know enough about the benefits/drawbacks of interning to say whether it's reasonable.
We know that it's an instance of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is it really all that bad? >>> s = sys.intern('spam and eggs')
>>> t = sys.intern('spam and eggs')
>>> s is t
True
>>> id(s)
139835455199152
>>> del s, t
>>> s = sys.intern('spam and eggs')
>>> id(s)
139835455198912 |
||
return drv, root, parsed | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix incorrect normalization of UNC device path roots, and partial UNC share | ||
path roots, in :class:`pathlib.PurePath`. Pathlib no longer appends a | ||
trailing slash to such paths. |
Uh oh!
There was an error while loading. Please reload this page.