mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
GH-78079: Fix UNC device path root normalization in pathlib (GH-102003)
We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`. Co-authored-by: Eryk Sun <eryksun@gmail.com>
This commit is contained in:
parent
7c1b0a46c6
commit
8af8f52d17
4 changed files with 43 additions and 3 deletions
|
|
@ -169,6 +169,7 @@ def test_splitroot(self):
|
|||
|
||||
# gh-81790: support device namespace, including UNC drives.
|
||||
tester('ntpath.splitroot("//?/c:")', ("//?/c:", "", ""))
|
||||
tester('ntpath.splitroot("//./c:")', ("//./c:", "", ""))
|
||||
tester('ntpath.splitroot("//?/c:/")', ("//?/c:", "/", ""))
|
||||
tester('ntpath.splitroot("//?/c:/dir")', ("//?/c:", "/", "dir"))
|
||||
tester('ntpath.splitroot("//?/UNC")', ("//?/UNC", "", ""))
|
||||
|
|
@ -179,8 +180,12 @@ def test_splitroot(self):
|
|||
tester('ntpath.splitroot("//?/VOLUME{00000000-0000-0000-0000-000000000000}/spam")',
|
||||
('//?/VOLUME{00000000-0000-0000-0000-000000000000}', '/', 'spam'))
|
||||
tester('ntpath.splitroot("//?/BootPartition/")', ("//?/BootPartition", "/", ""))
|
||||
tester('ntpath.splitroot("//./BootPartition/")', ("//./BootPartition", "/", ""))
|
||||
tester('ntpath.splitroot("//./PhysicalDrive0")', ("//./PhysicalDrive0", "", ""))
|
||||
tester('ntpath.splitroot("//./nul")', ("//./nul", "", ""))
|
||||
|
||||
tester('ntpath.splitroot("\\\\?\\c:")', ("\\\\?\\c:", "", ""))
|
||||
tester('ntpath.splitroot("\\\\.\\c:")', ("\\\\.\\c:", "", ""))
|
||||
tester('ntpath.splitroot("\\\\?\\c:\\")', ("\\\\?\\c:", "\\", ""))
|
||||
tester('ntpath.splitroot("\\\\?\\c:\\dir")', ("\\\\?\\c:", "\\", "dir"))
|
||||
tester('ntpath.splitroot("\\\\?\\UNC")', ("\\\\?\\UNC", "", ""))
|
||||
|
|
@ -193,6 +198,9 @@ def test_splitroot(self):
|
|||
tester('ntpath.splitroot("\\\\?\\VOLUME{00000000-0000-0000-0000-000000000000}\\spam")',
|
||||
('\\\\?\\VOLUME{00000000-0000-0000-0000-000000000000}', '\\', 'spam'))
|
||||
tester('ntpath.splitroot("\\\\?\\BootPartition\\")', ("\\\\?\\BootPartition", "\\", ""))
|
||||
tester('ntpath.splitroot("\\\\.\\BootPartition\\")', ("\\\\.\\BootPartition", "\\", ""))
|
||||
tester('ntpath.splitroot("\\\\.\\PhysicalDrive0")', ("\\\\.\\PhysicalDrive0", "", ""))
|
||||
tester('ntpath.splitroot("\\\\.\\nul")', ("\\\\.\\nul", "", ""))
|
||||
|
||||
# gh-96290: support partial/invalid UNC drives
|
||||
tester('ntpath.splitroot("//")', ("//", "", "")) # empty server & missing share
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue