mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)
This commit is contained in:
parent
dd53b79de0
commit
aab01e3524
10 changed files with 65 additions and 21 deletions
|
@ -544,7 +544,7 @@ if 1:
|
|||
with open(fn, "wb") as fp:
|
||||
fp.write(src)
|
||||
res = script_helper.run_python_until_end(fn)[0]
|
||||
self.assertIn(b"Non-UTF-8", res.err)
|
||||
self.assertIn(b"source code cannot contain null bytes", res.err)
|
||||
|
||||
def test_yet_more_evil_still_undecodable(self):
|
||||
# Issue #25388
|
||||
|
@ -554,7 +554,7 @@ if 1:
|
|||
with open(fn, "wb") as fp:
|
||||
fp.write(src)
|
||||
res = script_helper.run_python_until_end(fn)[0]
|
||||
self.assertIn(b"Non-UTF-8", res.err)
|
||||
self.assertIn(b"source code cannot contain null bytes", res.err)
|
||||
|
||||
@support.cpython_only
|
||||
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
|
||||
|
@ -591,9 +591,9 @@ if 1:
|
|||
def test_null_terminated(self):
|
||||
# The source code is null-terminated internally, but bytes-like
|
||||
# objects are accepted, which could be not terminated.
|
||||
with self.assertRaisesRegex(ValueError, "cannot contain null"):
|
||||
with self.assertRaisesRegex(SyntaxError, "cannot contain null"):
|
||||
compile("123\x00", "<dummy>", "eval")
|
||||
with self.assertRaisesRegex(ValueError, "cannot contain null"):
|
||||
with self.assertRaisesRegex(SyntaxError, "cannot contain null"):
|
||||
compile(memoryview(b"123\x00"), "<dummy>", "eval")
|
||||
code = compile(memoryview(b"123\x00")[1:-1], "<dummy>", "eval")
|
||||
self.assertEqual(eval(code), 23)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue