Issue 33898: pathlib issues with Windows device paths (original) (raw)
For \?\ extended device paths, pathlib removes the trailing slash for the root directory if the device isn't UNC or a logical (A-Z) drive.
Correct:
>>> str(Path('//?/UNC/'))
'\\\\?\\UNC\\'
>>> str(Path('//?/Z:/'))
'\\\\?\\Z:\\'
Incorrect:
>>> str(Path('//?/BootPartition/'))
'\\\\?\\BootPartition'
>>> str(Path('//?/Volume{}/'))
'\\\\?\\Volume{}'
>>> str(Path('//?/Global/Z:/'))
'\\\\?\\Global\\Z:'
It keeps the trailing slash for some \.\ paths, but not all.
Correct:
>>> str(Path('//./BootPartition/'))
'\\\\.\\BootPartition\\'
Incorrect:
>>> str(Path('//./Global/Z:/'))
'\\\\.\\Global\\Z:'
It adds a root directory to \.\ device paths where none was specified.
Incorrect:
>>> str(Path('//./nul'))
'\\\\.\\nul\\'
>>> str(Path('//./PhysicalDrive0'))
'\\\\.\\PhysicalDrive0\\'
>>> str(Path('//./C:'))
'\\\\.\\C:\\'
"\\.\C:" refers to the volume device, whereas "\\.\C:\" is the root directory in the file system.
pathlib should parse \?\ and \.\ device paths the same way with respect to the drive and root. The difference in practice is only how Windows does (\.) or does not (\?) canonicalize the path.
Additionally, pathlib fails to identify the drive correctly in these cases.
Incorrect:
>>> Path('//?/Global/Z:/').drive
'\\\\?\\'
>>> Path('//?/BootPartition/Temp').drive
'\\\\?\\'
Except for "UNC" and "Global" paths, the drive should be the first component after the local-device prefix. The "UNC" device also includes subsequent server and share components, if any. For the reserved "Global" symlink, it should look to the next component. For example, r'\?\Global\UNC\server\share' is a drive.
There's also the "GlobalRoot" symlink (or "Global\GlobalRoot" to be pedantic), but that can't be handled generically.