mirror of https://github.com/python/cpython
gh-107967: Fix infinite recursion on invalid escape sequence warning (#107968)
This commit is contained in:
parent
13c36dc9ae
commit
d66bc9e8a7
|
@ -1673,5 +1673,15 @@ print(f'''{{
|
||||||
self.assertEqual(stdout.decode('utf-8').strip().replace('\r\n', '\n').replace('\r', '\n'),
|
self.assertEqual(stdout.decode('utf-8').strip().replace('\r\n', '\n').replace('\r', '\n'),
|
||||||
"3\n=3")
|
"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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1539,6 +1539,9 @@ error:
|
||||||
static int
|
static int
|
||||||
warn_invalid_escape_sequence(struct tok_state *tok, int first_invalid_escape_char)
|
warn_invalid_escape_sequence(struct tok_state *tok, int first_invalid_escape_char)
|
||||||
{
|
{
|
||||||
|
if (!tok->report_warnings) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *msg = PyUnicode_FromFormat(
|
PyObject *msg = PyUnicode_FromFormat(
|
||||||
"invalid escape sequence '\\%c'",
|
"invalid escape sequence '\\%c'",
|
||||||
|
|
Loading…
Reference in New Issue