@@ -483,9 +483,16 @@ def test_realpath_strict(self):
483483 self .addCleanup (os_helper .unlink , ABSTFN )
484484 self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN , strict = True )
485485 self .assertRaises (FileNotFoundError , ntpath .realpath , ABSTFN + "2" , strict = True )
486- # gh-106242: Embedded nulls should raise OSError (not ValueError)
487- self .assertRaises (OSError , ntpath .realpath , ABSTFN + "\0 spam" , strict = True )
488486
487+ @unittest .skipUnless (HAVE_GETFINALPATHNAME , 'need _getfinalpathname' )
488+ def test_realpath_invalid_paths (self ):
489+ realpath = ntpath .realpath
490+ ABSTFN = ntpath .abspath (os_helper .TESTFN )
491+ ABSTFNb = os .fsencode (ABSTFN )
492+ path = ABSTFN + '\x00 '
493+ # gh-106242: Embedded nulls and non-strict fallback to abspath
494+ self .assertEqual (realpath (path , strict = False ), path )
495+ # gh-106242: Embedded nulls should raise OSError (not ValueError)
489496 self .assertRaises (OSError , ntpath .realpath , path , strict = True )
490497 self .assertRaises (OSError , ntpath .realpath , path , strict = ALLOW_MISSING )
491498 path = ABSTFNb + b'\x00 '
0 commit comments