@@ -421,9 +421,16 @@ def test_realpath_strict(self):
421421 self .addCleanup (os_helper .unlink , ABSTFN )
422422 self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN , strict = True )
423423 self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN + "2" , strict = True )
424- # gh-106242: Embedded nulls should raise OSError (not ValueError)
425- self .assertRaises (OSError , ntpath .realpath , ABSTFN + "\0 spam" , strict = True )
426424
425+ @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
426+ def test_realpath_invalid_paths (self ):
427+ realpath = ntpath .realpath
428+ ABSTFN = ntpath .abspath (os_helper .TESTFN )
429+ ABSTFNb = os .fsencode (ABSTFN )
430+ path = ABSTFN + '\x00 '
431+ # gh-106242: Embedded nulls and non-strict fallback to abspath
432+ self .assertEqual (realpath (path , strict = False ), path )
433+ # gh-106242: Embedded nulls should raise OSError (not ValueError)
427434 self .assertRaises (OSError , ntpath .realpath , path , strict = True )
428435 self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
429436 path = ABSTFNb + b'\x00 '
0 commit comments