summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ntpath.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2023-08-22 00:16:02 (GMT)
committerGitHub <noreply@github.com>2023-08-22 00:16:02 (GMT)
commitde33b5c662ea8d35d81ed857c6a39e34ab94c510 (patch)
treea80880d153261078923dc275cc2421f18e2350a9 /Lib/test/test_ntpath.py
parent531930f47f6b2a548d31e62cb4ad3e215a24bf53 (diff)
downloadcpython-de33b5c662ea8d35d81ed857c6a39e34ab94c510.zip
cpython-de33b5c662ea8d35d81ed857c6a39e34ab94c510.tar.gz
cpython-de33b5c662ea8d35d81ed857c6a39e34ab94c510.tar.bz2
gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
* gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_ntpath.py')
-rw-r--r--Lib/test/test_ntpath.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 78e1cb5..d91dcdf 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -394,6 +394,10 @@ class TestNtpath(NtpathTestCase):
d = drives.pop().encode()
self.assertEqual(ntpath.realpath(d), d)
+ # gh-106242: Embedded nulls and non-strict fallback to abspath
+ self.assertEqual(ABSTFN + "\0spam",
+ ntpath.realpath(os_helper.TESTFN + "\0spam", strict=False))
+
@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_strict(self):
@@ -404,6 +408,8 @@ class TestNtpath(NtpathTestCase):
self.addCleanup(os_helper.unlink, ABSTFN)
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN, strict=True)
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN + "2", strict=True)
+ # gh-106242: Embedded nulls should raise OSError (not ValueError)
+ self.assertRaises(OSError, ntpath.realpath, ABSTFN + "\0spam", strict=True)
@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')