mirror of
https://github.com/python/cpython.git
synced 2025-08-29 13:15:11 +00:00
bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)
Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(), os.path.isfile(), os.path.islink(), and os.path.ismount() now return False instead of raising ValueError or its subclasses UnicodeEncodeError and UnicodeDecodeError for paths that contain characters or bytes unrepresentative at the OS level.
This commit is contained in:
parent
7bdf28265a
commit
0185f34ddc
15 changed files with 181 additions and 54 deletions
|
@ -153,9 +153,11 @@ class PosixPathTest(unittest.TestCase):
|
|||
def test_islink(self):
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
|
||||
self.assertIs(posixpath.lexists(support.TESTFN + "2"), False)
|
||||
|
||||
with open(support.TESTFN + "1", "wb") as f:
|
||||
f.write(b"foo")
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
|
||||
|
||||
if support.can_symlink():
|
||||
os.symlink(support.TESTFN + "1", support.TESTFN + "2")
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
|
||||
|
@ -164,6 +166,11 @@ class PosixPathTest(unittest.TestCase):
|
|||
self.assertIs(posixpath.exists(support.TESTFN + "2"), False)
|
||||
self.assertIs(posixpath.lexists(support.TESTFN + "2"), True)
|
||||
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "\udfff"), False)
|
||||
self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\xff"), False)
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "\x00"), False)
|
||||
self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\x00"), False)
|
||||
|
||||
def test_ismount(self):
|
||||
self.assertIs(posixpath.ismount("/"), True)
|
||||
self.assertIs(posixpath.ismount(b"/"), True)
|
||||
|
@ -177,6 +184,11 @@ class PosixPathTest(unittest.TestCase):
|
|||
finally:
|
||||
safe_rmdir(ABSTFN)
|
||||
|
||||
self.assertIs(posixpath.ismount('/\udfff'), False)
|
||||
self.assertIs(posixpath.ismount(b'/\xff'), False)
|
||||
self.assertIs(posixpath.ismount('/\x00'), False)
|
||||
self.assertIs(posixpath.ismount(b'/\x00'), False)
|
||||
|
||||
@unittest.skipUnless(support.can_symlink(),
|
||||
"Test requires symlink support")
|
||||
def test_ismount_symlinks(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue