@@ -107,22 +107,22 @@ def test_splitdrive(self):
107
107
tester ('ntpath.splitdrive("//conky/mountpoint/foo/bar")' ,
108
108
('//conky/mountpoint' , '/foo/bar' ))
109
109
tester ('ntpath.splitdrive("\\ \\ \\ conky\\ mountpoint\\ foo\\ bar")' ,
110
- ('' , ' \\ \\ \\ conky\\ mountpoint\\ foo\\ bar' ))
110
+ ('\\ \\ \\ conky' , ' \\ mountpoint\\ foo\\ bar' ))
111
111
tester ('ntpath.splitdrive("///conky/mountpoint/foo/bar")' ,
112
- ('' , ' ///conky/mountpoint/foo/bar' ))
112
+ ('///conky' , ' /mountpoint/foo/bar' ))
113
113
tester ('ntpath.splitdrive("\\ \\ conky\\ \\ mountpoint\\ foo\\ bar")' ,
114
- ('' , ' \\ \\ conky\\ \\ mountpoint\\ foo\\ bar' ))
114
+ ('\\ \\ conky\\ ' , ' \\ mountpoint\\ foo\\ bar' ))
115
115
tester ('ntpath.splitdrive("//conky//mountpoint/foo/bar")' ,
116
- ('' , ' //conky//mountpoint/foo/bar' ))
116
+ ('//conky/' , ' /mountpoint/foo/bar' ))
117
117
# Issue #19911: UNC part containing U+0130
118
118
self .assertEqual (ntpath .splitdrive ('//conky/MOUNTPOİNT/foo/bar' ),
119
119
('//conky/MOUNTPOİNT' , '/foo/bar' ))
120
120
# gh-81790: support device namespace, including UNC drives.
121
121
tester ('ntpath.splitdrive("//?/c:")' , ("//?/c:" , "" ))
122
122
tester ('ntpath.splitdrive("//?/c:/")' , ("//?/c:" , "/" ))
123
123
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/" , " " ))
126
126
tester ('ntpath.splitdrive("//?/UNC/server/")' , ("//?/UNC/server/" , "" ))
127
127
tester ('ntpath.splitdrive("//?/UNC/server/share")' , ("//?/UNC/server/share" , "" ))
128
128
tester ('ntpath.splitdrive("//?/UNC/server/share/dir")' , ("//?/UNC/server/share" , "/dir" ))
@@ -133,8 +133,8 @@ def test_splitdrive(self):
133
133
tester ('ntpath.splitdrive("\\ \\ ?\\ c:")' , ("\\ \\ ?\\ c:" , "" ))
134
134
tester ('ntpath.splitdrive("\\ \\ ?\\ c:\\ ")' , ("\\ \\ ?\\ c:" , "\\ " ))
135
135
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\\ " , " " ))
138
138
tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ ")' , ("\\ \\ ?\\ UNC\\ server\\ " , "" ))
139
139
tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share")' , ("\\ \\ ?\\ UNC\\ server\\ share" , "" ))
140
140
tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share\\ dir")' ,
@@ -143,6 +143,13 @@ def test_splitdrive(self):
143
143
('\\ \\ ?\\ VOLUME{00000000-0000-0000-0000-000000000000}' , '\\ spam' ))
144
144
tester ('ntpath.splitdrive("\\ \\ ?\\ BootPartition\\ ")' , ("\\ \\ ?\\ BootPartition" , "\\ " ))
145
145
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 & valid share
150
+ tester ('ntpath.splitdrive("//x")' , ("//x" , "" )) # valid server & missing share
151
+ tester ('ntpath.splitdrive("//x/")' , ("//x/" , "" )) # valid server & empty share
152
+
146
153
def test_split (self ):
147
154
tester ('ntpath.split("c:\\ foo\\ bar")' , ('c:\\ foo' , 'bar' ))
148
155
tester ('ntpath.split("\\ \\ conky\\ mountpoint\\ foo\\ bar")' ,
@@ -270,6 +277,13 @@ def test_normpath(self):
270
277
tester ("ntpath.normpath('//server/share/../..')" , '\\ \\ server\\ share\\ ' )
271
278
tester ("ntpath.normpath('//server/share/../../')" , '\\ \\ server\\ share\\ ' )
272
279
280
+ # gh-96290: don't normalize partial/invalid UNC drives
281
+ tester ("ntpath.normpath('\\ \\ foo\\ bar')" , '\\ \\ foo\\ bar' )
282
+ tester ("ntpath.normpath('\\ \\ foo\\ \\ ')" , '\\ \\ foo\\ \\ ' )
283
+ tester ("ntpath.normpath('\\ \\ foo\\ ')" , '\\ \\ foo\\ ' )
284
+ tester ("ntpath.normpath('\\ \\ foo')" , '\\ \\ foo' )
285
+ tester ("ntpath.normpath('\\ \\ ')" , '\\ \\ ' )
286
+
273
287
def test_realpath_curdir (self ):
274
288
expected = ntpath .normpath (os .getcwd ())
275
289
tester ("ntpath.realpath('.')" , expected )
0 commit comments