@@ -489,11 +489,37 @@ def test_realpath_strict(self):
489489        finally :
490490            os_helper .unlink (ABSTFN )
491491
492+     def  test_realpath_embedded_null (self ):
493+         path  =  '/\x00 ' 
494+         self .assertRaises (ValueError , realpath , path , strict = False )
495+         self .assertRaises (ValueError , realpath , path , strict = True )
496+         path  =  b'/\x00 ' 
497+         self .assertRaises (ValueError , realpath , path , strict = False )
498+         self .assertRaises (ValueError , realpath , path , strict = True )
499+         path  =  '/nonexistent/x\x00 ' 
500+         self .assertRaises (ValueError , realpath , path , strict = False )
501+         self .assertRaises (FileNotFoundError , realpath , path , strict = True )
502+         path  =  b'/nonexistent/x\x00 ' 
503+         self .assertRaises (ValueError , realpath , path , strict = False )
504+         self .assertRaises (FileNotFoundError , realpath , path , strict = True )
505+ 
506+     @unittest .skipIf (sys .platform  ==  'win32' , 'requires native bytes paths' ) 
492507    def  test_realpath_unencodable (self ):
493-         self .assertRaises (ValueError , realpath , 'test\0 ' , strict = False )
494-         self .assertRaises (ValueError , realpath , 'test\0 ' , strict = True )
495-         self .assertRaises (UnicodeEncodeError , realpath , '\ud800 ' , strict = False )
496-         self .assertRaises (UnicodeEncodeError , realpath , '\ud800 ' , strict = True )
508+         path  =  '/\ud800 ' 
509+         self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
510+         self .assertRaises (UnicodeEncodeError , realpath , path , strict = True )
511+         path  =  '/nonexistent/\ud800 ' 
512+         self .assertRaises (UnicodeEncodeError , realpath , path , strict = False )
513+         self .assertRaises (FileNotFoundError , realpath , path , strict = True )
514+ 
515+     @unittest .skipUnless (sys .platform  ==  'win32' , 'requires native Unicode paths' ) 
516+     def  test_realpath_undecodable (self ):
517+         path  =  b'/\xff ' 
518+         self .assertRaises (UnicodeDecodeError , realpath , path , strict = False )
519+         self .assertRaises (UnicodeDecodeError , realpath , path , strict = True )
520+         path  =  b'/nonexistent/\xff ' 
521+         self .assertRaises (UnicodeDecodeError , realpath , path , strict = False )
522+         self .assertRaises (FileNotFoundError , realpath , path , strict = True )
497523
498524    @os_helper .skip_unless_symlink  
499525    @skip_if_ABSTFN_contains_backslash  
0 commit comments