gh-81790: support "UNC" device paths in ntpath.splitdrive() (GH-91882)

This commit is contained in:
Barney Gale 2022-06-10 16:59:55 +01:00 committed by GitHub
parent 53a8b17895
commit 2ba0fd5767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 66 deletions

View file

@ -172,17 +172,23 @@ def splitdrive(p):
sep = b'\\'
altsep = b'/'
colon = b':'
unc_prefix = b'\\\\?\\UNC'
else:
sep = '\\'
altsep = '/'
colon = ':'
unc_prefix = '\\\\?\\UNC'
normp = p.replace(altsep, sep)
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^^
index = normp.find(sep, 2)
if normp[:8].upper().rstrip(sep) == unc_prefix:
start = 8
else:
start = 2
index = normp.find(sep, start)
if index == -1:
return p[:0], p
index2 = normp.find(sep, index + 1)