@@ -138,10 +138,20 @@ def test_exists(self):
138138 self .assertIs (self .pathmodule .exists (filename ), True )
139139 self .assertIs (self .pathmodule .exists (bfilename ), True )
140140
141+ self .assertIs (self .pathmodule .exists (filename + '\udfff ' ), False )
142+ self .assertIs (self .pathmodule .exists (bfilename + b'\xff ' ), False )
143+ self .assertIs (self .pathmodule .exists (filename + '\x00 ' ), False )
144+ self .assertIs (self .pathmodule .exists (bfilename + b'\x00 ' ), False )
145+
141146 if self .pathmodule is not genericpath :
142147 self .assertIs (self .pathmodule .lexists (filename ), True )
143148 self .assertIs (self .pathmodule .lexists (bfilename ), True )
144149
150+ self .assertIs (self .pathmodule .lexists (filename + '\udfff ' ), False )
151+ self .assertIs (self .pathmodule .lexists (bfilename + b'\xff ' ), False )
152+ self .assertIs (self .pathmodule .lexists (filename + '\x00 ' ), False )
153+ self .assertIs (self .pathmodule .lexists (bfilename + b'\x00 ' ), False )
154+
145155 @unittest .skipUnless (hasattr (os , "pipe" ), "requires os.pipe()" )
146156 def test_exists_fd (self ):
147157 r , w = os .pipe ()
@@ -158,6 +168,11 @@ def test_isdir(self):
158168 self .assertIs (self .pathmodule .isdir (filename ), False )
159169 self .assertIs (self .pathmodule .isdir (bfilename ), False )
160170
171+ self .assertIs (self .pathmodule .isdir (filename + '\udfff ' ), False )
172+ self .assertIs (self .pathmodule .isdir (bfilename + b'\xff ' ), False )
173+ self .assertIs (self .pathmodule .isdir (filename + '\x00 ' ), False )
174+ self .assertIs (self .pathmodule .isdir (bfilename + b'\x00 ' ), False )
175+
161176 try :
162177 create_file (filename )
163178 self .assertIs (self .pathmodule .isdir (filename ), False )
@@ -178,6 +193,11 @@ def test_isfile(self):
178193 self .assertIs (self .pathmodule .isfile (filename ), False )
179194 self .assertIs (self .pathmodule .isfile (bfilename ), False )
180195
196+ self .assertIs (self .pathmodule .isfile (filename + '\udfff ' ), False )
197+ self .assertIs (self .pathmodule .isfile (bfilename + b'\xff ' ), False )
198+ self .assertIs (self .pathmodule .isfile (filename + '\x00 ' ), False )
199+ self .assertIs (self .pathmodule .isfile (bfilename + b'\x00 ' ), False )
200+
181201 try :
182202 create_file (filename )
183203 self .assertIs (self .pathmodule .isfile (filename ), True )
@@ -298,18 +318,20 @@ def test_invalid_paths(self):
298318 continue
299319 func = getattr (self .pathmodule , attr )
300320 with self .subTest (attr = attr ):
301- try :
321+ if attr in ( 'exists' , 'isdir' , 'isfile' ) :
302322 func ('/tmp\udfff abcds' )
303- except (OSError , UnicodeEncodeError ):
304- pass
305- try :
306323 func (b'/tmp\xff abcds' )
307- except (OSError , UnicodeDecodeError ):
308- pass
309- with self .assertRaisesRegex (ValueError , 'embedded null' ):
310324 func ('/tmp\x00 abcds' )
311- with self .assertRaisesRegex (ValueError , 'embedded null' ):
312325 func (b'/tmp\x00 abcds' )
326+ else :
327+ with self .assertRaises ((OSError , UnicodeEncodeError )):
328+ func ('/tmp\udfff abcds' )
329+ with self .assertRaises ((OSError , UnicodeDecodeError )):
330+ func (b'/tmp\xff abcds' )
331+ with self .assertRaisesRegex (ValueError , 'embedded null' ):
332+ func ('/tmp\x00 abcds' )
333+ with self .assertRaisesRegex (ValueError , 'embedded null' ):
334+ func (b'/tmp\x00 abcds' )
313335
314336# Following TestCase is not supposed to be run from test_genericpath.
315337# It is inherited by other test modules (macpath, ntpath, posixpath).
0 commit comments