Skip to content

Commit

Permalink
Support also the \\?\UNC\ prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Nov 12, 2024
1 parent 2d27835 commit 1a4f514
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ def split(p):
def splitext(p):
p = os.fspath(p)
if isinstance(p, bytes):
seps = (b'\\', b'/')
prefixes = (b'\\\\', b'//', b'\\/', b'/\\')
root, ext = genericpath._splitext(p, b'\\', b'/', b'.')
else:
seps = ('\\', '/')
prefixes = ('\\\\', '//', '\\/', '/\\')
root, ext = genericpath._splitext(p, '\\', '/', '.')
if (ext and root[:1] in seps and root[1:2] in seps and
root.count(seps[0], 2) + root.count(seps[1], 2) <= 1):
if ext and root.startswith(prefixes) and not splitroot(root)[2]:
# \\server.ext or \\server\share.ext, but not \\server\share\path.ext
return p, p[:0]
return root, ext
splitext.__doc__ = genericpath._splitext.__doc__
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def test_splitext(self):
tester(r'ntpath.splitext("//server.ext")',
(r'//server.ext', ''))

tester(r'ntpath.splitext("\\?\UNC\server\share.ext")',
(r'\\?\UNC\server\share.ext', ''))
tester(r'ntpath.splitext("//?/UNC/server/share.ext")',
(r'//?/UNC/server/share.ext', ''))
tester(r'ntpath.splitext("\\?\UNC\server.ext")',
(r'\\?\UNC\server.ext', ''))
tester(r'ntpath.splitext("//?/UNC/server.ext")',
(r'//?/UNC/server.ext', ''))

tester(r'ntpath.splitext("\\server\share\file.ext")',
(r'\\server\share\file', '.ext'))
tester(r'ntpath.splitext("//server/share/file.ext")',
Expand All @@ -117,6 +126,10 @@ def test_splitext(self):
(r'\\server\share/file', '.ext'))
tester(r'ntpath.splitext("//server/share\file.ext")',
(r'//server/share\file', '.ext'))
tester(r'ntpath.splitext("\\?\UNC\server\share\file.ext")',
(r'\\?\UNC\server\share\file', '.ext'))
tester(r'ntpath.splitext("//?/UNC/server/share/file.ext")',
(r'//?/UNC/server/share/file', '.ext'))

def test_splitdrive(self):
tester("ntpath.splitdrive('')", ('', ''))
Expand Down

0 comments on commit 1a4f514

Please sign in to comment.