diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-15 12:41:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-15 12:41:55 (GMT) |
commit | d189480942348aab345500ac9204965f67f30210 (patch) | |
tree | 9c3875ce2cec11e1eaaa98aa3c07be495f914de8 | |
parent | e8963a86ead0f5516948b3ad55b410b7fc5fb194 (diff) | |
download | cpython-d189480942348aab345500ac9204965f67f30210.zip cpython-d189480942348aab345500ac9204965f67f30210.tar.gz cpython-d189480942348aab345500ac9204965f67f30210.tar.bz2 |
[3.12] gh-107967: Fix infinite recursion on invalid escape sequence warning (GH-107968) (#107970)
gh-107967: Fix infinite recursion on invalid escape sequence warning (GH-107968)
(cherry picked from commit d66bc9e8a7a8d6774d912a4b9d151885c4d8de1d)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
-rw-r--r-- | Lib/test/test_fstring.py | 10 | ||||
-rw-r--r-- | Parser/tokenizer.c | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index cb14bba..16f0197 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -1673,5 +1673,15 @@ print(f'''{{ self.assertEqual(stdout.decode('utf-8').strip().replace('\r\n', '\n').replace('\r', '\n'), "3\n=3") + def test_syntax_warning_infinite_recursion_in_file(self): + with temp_cwd(): + script = 'script.py' + with open(script, 'w') as f: + f.write(r"print(f'\{1}')") + + _, stdout, stderr = assert_python_ok(script) + self.assertIn(rb'\1', stdout) + self.assertEqual(len(stderr.strip().splitlines()), 2) + if __name__ == '__main__': unittest.main() diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 7e246d2..c4c345e 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1544,6 +1544,9 @@ error: static int warn_invalid_escape_sequence(struct tok_state *tok, int first_invalid_escape_char) { + if (!tok->report_warnings) { + return 0; + } PyObject *msg = PyUnicode_FromFormat( "invalid escape sequence '\\%c'", |