@@ -107,22 +107,22 @@ def test_splitdrive(self):
107107 tester ('ntpath.splitdrive("//conky/mountpoint/foo/bar")' ,
108108 ('//conky/mountpoint' , '/foo/bar' ))
109109 tester ('ntpath.splitdrive("\\ \\ \\ conky\\ mountpoint\\ foo\\ bar")' ,
110- ('' , ' \\ \\ \\ conky\\ mountpoint\\ foo\\ bar' ))
110+ ('\\ \\ \\ conky' , ' \\ mountpoint\\ foo\\ bar' ))
111111 tester ('ntpath.splitdrive("///conky/mountpoint/foo/bar")' ,
112- ('' , ' ///conky/mountpoint/foo/bar' ))
112+ ('///conky' , ' /mountpoint/foo/bar' ))
113113 tester ('ntpath.splitdrive("\\ \\ conky\\ \\ mountpoint\\ foo\\ bar")' ,
114- ('' , ' \\ \\ conky\\ \\ mountpoint\\ foo\\ bar' ))
114+ ('\\ \\ conky\\ ' , ' \\ mountpoint\\ foo\\ bar' ))
115115 tester ('ntpath.splitdrive("//conky//mountpoint/foo/bar")' ,
116- ('' , ' //conky//mountpoint/foo/bar' ))
116+ ('//conky/' , ' /mountpoint/foo/bar' ))
117117 # Issue #19911: UNC part containing U+0130
118118 self .assertEqual (ntpath .splitdrive ('//conky/MOUNTPOİNT/foo/bar' ),
119119 ('//conky/MOUNTPOİNT' , '/foo/bar' ))
120120 # gh-81790: support device namespace, including UNC drives.
121121 tester ('ntpath.splitdrive("//?/c:")' , ("//?/c:" , "" ))
122122 tester ('ntpath.splitdrive("//?/c:/")' , ("//?/c:" , "/" ))
123123 tester ('ntpath.splitdrive("//?/c:/dir")' , ("//?/c:" , "/dir" ))
124- tester ('ntpath.splitdrive("//?/UNC")' , ("" , " //?/UNC" ))
125- tester ('ntpath.splitdrive("//?/UNC/")' , ("" , " //?/UNC/" ))
124+ tester ('ntpath.splitdrive("//?/UNC")' , ("//?/UNC" , " " ))
125+ tester ('ntpath.splitdrive("//?/UNC/")' , ("//?/UNC/" , " " ))
126126 tester ('ntpath.splitdrive("//?/UNC/server/")' , ("//?/UNC/server/" , "" ))
127127 tester ('ntpath.splitdrive("//?/UNC/server/share")' , ("//?/UNC/server/share" , "" ))
128128 tester('ntpath.splitdrive("//?/UNC/server/share/dir")' , ("//?/UNC/server/share" , "/dir" ))
@@ -133,8 +133,8 @@ def test_splitdrive(self):
133133 tester ('ntpath.splitdrive("\\ \\ ?\\ c:")' , ("\\ \\ ?\\ c:" , "" ))
134134 tester ('ntpath.splitdrive("\\ \\ ?\\ c:\\ ")' , ("\\ \\ ?\\ c:" , "\\ " ))
135135 tester ('ntpath.splitdrive("\\ \\ ?\\ c:\\ dir")' , ("\\ \\ ?\\ c:" , "\\ dir" ))
136- tester ('ntpath.splitdrive("\\ \\ ?\\ UNC")' , ("" , " \\ \\ ?\\ UNC" ))
137- tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ ")' , ("" , " \\ \\ ?\\ UNC\\ " ))
136+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC")' , ("\\ \\ ?\\ UNC" , " " ))
137+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ ")' , ("\\ \\ ?\\ UNC\\ " , " " ))
138138 tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ ")' , ("\\ \\ ?\\ UNC\\ server\\ " , "" ))
139139 tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share")' , ("\\ \\ ?\\ UNC\\ server\\ share" , "" ))
140140 tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share\\ dir")' ,
@@ -143,6 +143,13 @@ def test_splitdrive(self):
143143 ('\\ \\ ?\\ VOLUME{00000000-0000-0000-0000-000000000000}' , '\\ spam' ))
144144 tester ('ntpath.splitdrive("\\ \\ ?\\ BootPartition\\ ")' , ("\\ \\ ?\\ BootPartition" , "\\ " ))
145145
146+ # gh-96290: support partial/invalid UNC drives
147+ tester ('ntpath.splitdrive("//")' , ("//" , "" )) # empty server & missing share
148+ tester ('ntpath.splitdrive("///")' , ("///" , "" )) # empty server & empty share
149+ tester ('ntpath.splitdrive("///y")' , ("///y" , "" )) # empty server & non-empty share
150+ tester ('ntpath.splitdrive("//x")' , ("//x" , "" )) # non-empty server & missing share
151+ tester ('ntpath.splitdrive("//x/")' , ("//x/" , "" )) # non-empty server & empty share
152+
146153 def test_split (self ):
147154 tester ('ntpath.split("c:\\ foo\\ bar")' , ('c:\\ foo' , 'bar' ))
148155 tester ('ntpath.split("\\ \\ conky\\ mountpoint\\ foo\\ bar")' ,
@@ -161,6 +168,10 @@ def test_isabs(self):
161168 tester ('ntpath.isabs("\\ foo")' , 1 )
162169 tester ('ntpath.isabs("\\ foo\\ bar")' , 1 )
163170
171+ # gh-96290: normal UNC paths and device paths without trailing backslashes
172+ tester ('ntpath.isabs("\\ \\ conky\\ mountpoint")' , 1 )
173+ tester ('ntpath.isabs("\\ \\ .\\ C:")' , 1 )
174+
164175 def test_commonprefix (self ):
165176 tester ('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])' ,
166177 "/home/swen" )
@@ -270,6 +281,12 @@ def test_normpath(self):
270281 tester ("ntpath.normpath('//server/share/../..')" , '\\ \\ server\\ share\\ ' )
271282 tester ("ntpath.normpath('//server/share/../../')" , '\\ \\ server\\ share\\ ' )
272283
284+ # gh-96290: don't normalize partial/invalid UNC drives as rooted paths.
285+ tester ("ntpath.normpath('\\ \\ foo\\ \\ ')" , '\\ \\ foo\\ \\ ' )
286+ tester ("ntpath.normpath('\\ \\ foo\\ ')" , '\\ \\ foo\\ ' )
287+ tester ("ntpath.normpath('\\ \\ foo')" , '\\ \\ foo' )
288+ tester ("ntpath.normpath('\\ \\ ')" , '\\ \\ ' )
289+
273290 def test_realpath_curdir (self ):
274291 expected = ntpath .normpath (os .getcwd ())
275292 tester ("ntpath.realpath('.')" , expected )
0 commit comments