@@ -107,17 +107,50 @@ 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
121
+ # gh-81790: support device namespace, including UNC drives.
122
+ tester ('ntpath.splitdrive("//?/c:")' , ("//?/c:" , "" ))
123
+ tester ('ntpath.splitdrive("//?/c:/")' , ("//?/c:" , "/" ))
124
+ tester ('ntpath.splitdrive("//?/c:/dir")' , ("//?/c:" , "/dir" ))
125
+ tester ('ntpath.splitdrive("//?/UNC")' , ("//?/UNC" , "" ))
126
+ tester ('ntpath.splitdrive("//?/UNC/")' , ("//?/UNC/" , "" ))
127
+ tester ('ntpath.splitdrive("//?/UNC/server/")' , ("//?/UNC/server/" , "" ))
128
+ tester ('ntpath.splitdrive("//?/UNC/server/share")' , ("//?/UNC/server/share" , "" ))
129
+ tester ('ntpath.splitdrive("//?/UNC/server/share/dir")' , ("//?/UNC/server/share" , "/dir" ))
130
+ tester ('ntpath.splitdrive("//?/VOLUME{00000000-0000-0000-0000-000000000000}/spam")' ,
131
+ ('//?/VOLUME{00000000-0000-0000-0000-000000000000}' , '/spam' ))
132
+ tester ('ntpath.splitdrive("//?/BootPartition/")' , ("//?/BootPartition" , "/" ))
133
+
134
+ tester ('ntpath.splitdrive("\\ \\ ?\\ c:")' , ("\\ \\ ?\\ c:" , "" ))
135
+ tester ('ntpath.splitdrive("\\ \\ ?\\ c:\\ ")' , ("\\ \\ ?\\ c:" , "\\ " ))
136
+ tester ('ntpath.splitdrive("\\ \\ ?\\ c:\\ dir")' , ("\\ \\ ?\\ c:" , "\\ dir" ))
137
+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC")' , ("\\ \\ ?\\ UNC" , "" ))
138
+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ ")' , ("\\ \\ ?\\ UNC\\ " , "" ))
139
+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ ")' , ("\\ \\ ?\\ UNC\\ server\\ " , "" ))
140
+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share")' , ("\\ \\ ?\\ UNC\\ server\\ share" , "" ))
141
+ tester ('ntpath.splitdrive("\\ \\ ?\\ UNC\\ server\\ share\\ dir")' ,
142
+ ("\\ \\ ?\\ UNC\\ server\\ share" , "\\ dir" ))
143
+ tester ('ntpath.splitdrive("\\ \\ ?\\ VOLUME{00000000-0000-0000-0000-000000000000}\\ spam")' ,
144
+ ('\\ \\ ?\\ VOLUME{00000000-0000-0000-0000-000000000000}' , '\\ spam' ))
145
+ tester ('ntpath.splitdrive("\\ \\ ?\\ BootPartition\\ ")' , ("\\ \\ ?\\ BootPartition" , "\\ " ))
146
+
147
+ # gh-96290: support partial/invalid UNC drives
148
+ tester ('ntpath.splitdrive("//")' , ("//" , "" )) # empty server & missing share
149
+ tester ('ntpath.splitdrive("///")' , ("///" , "" )) # empty server & empty share
150
+ tester ('ntpath.splitdrive("///y")' , ("///y" , "" )) # empty server & non-empty share
151
+ tester ('ntpath.splitdrive("//x")' , ("//x" , "" )) # non-empty server & missing share
152
+ tester ('ntpath.splitdrive("//x/")' , ("//x/" , "" )) # non-empty server & empty share
153
+
121
154
def test_split (self ):
122
155
tester ('ntpath.split("c:\\ foo\\ bar")' , ('c:\\ foo' , 'bar' ))
123
156
tester ('ntpath.split("\\ \\ conky\\ mountpoint\\ foo\\ bar")' ,
@@ -136,6 +169,10 @@ def test_isabs(self):
136
169
tester ('ntpath.isabs("\\ foo")' , 1 )
137
170
tester ('ntpath.isabs("\\ foo\\ bar")' , 1 )
138
171
172
+ # gh-96290: normal UNC paths and device paths without trailing backslashes
173
+ tester ('ntpath.isabs("\\ \\ conky\\ mountpoint")' , 1 )
174
+ tester ('ntpath.isabs("\\ \\ .\\ C:")' , 1 )
175
+
139
176
def test_commonprefix (self ):
140
177
tester ('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])' ,
141
178
"/home/swen" )
@@ -245,6 +282,12 @@ def test_normpath(self):
245
282
tester ("ntpath.normpath('//server/share/../..')" , '\\ \\ server\\ share\\ ' )
246
283
tester ("ntpath.normpath('//server/share/../../')" , '\\ \\ server\\ share\\ ' )
247
284
285
+ # gh-96290: don't normalize partial/invalid UNC drives as rooted paths.
286
+ tester ("ntpath.normpath('\\ \\ foo\\ \\ ')" , '\\ \\ foo\\ \\ ' )
287
+ tester ("ntpath.normpath('\\ \\ foo\\ ')" , '\\ \\ foo\\ ' )
288
+ tester ("ntpath.normpath('\\ \\ foo')" , '\\ \\ foo' )
289
+ tester ("ntpath.normpath('\\ \\ ')" , '\\ \\ ' )
290
+
248
291
def test_realpath_curdir (self ):
249
292
expected = ntpath .normpath (os .getcwd ())
250
293
tester ("ntpath.realpath('.')" , expected )
0 commit comments