summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line_script.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-09-27 22:23:42 (GMT)
committerGitHub <noreply@github.com>2022-09-27 22:23:42 (GMT)
commitaab01e3524d966dca6e72c718a2c71403a14e47c (patch)
tree69e30e5354e49bc104177ab61ee8b39ccd24bf22 /Lib/test/test_cmd_line_script.py
parentdd53b79de0ea98af6a11481217a961daef4e9774 (diff)
downloadcpython-aab01e3524d966dca6e72c718a2c71403a14e47c.zip
cpython-aab01e3524d966dca6e72c718a2c71403a14e47c.tar.gz
cpython-aab01e3524d966dca6e72c718a2c71403a14e47c.tar.bz2
gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
-rw-r--r--Lib/test/test_cmd_line_script.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index 9e98edf..1ee3acd 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -657,6 +657,18 @@ class CmdLineTest(unittest.TestCase):
],
)
+ def test_syntaxerror_null_bytes(self):
+ script = "x = '\0' nothing to see here\n';import os;os.system('echo pwnd')\n"
+ with os_helper.temp_dir() as script_dir:
+ script_name = _make_test_script(script_dir, 'script', script)
+ exitcode, stdout, stderr = assert_python_failure(script_name)
+ self.assertEqual(
+ stderr.splitlines()[-2:],
+ [ b" x = '",
+ b'SyntaxError: source code cannot contain null bytes'
+ ],
+ )
+
def test_consistent_sys_path_for_direct_execution(self):
# This test case ensures that the following all give the same
# sys.path configuration: