mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-104016: Fixed off by 1 error in f string tokenizer (#104047)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Co-authored-by: Ken Jin <kenjin@python.org> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
parent
2d526cd32f
commit
5078eedc5b
3 changed files with 25 additions and 5 deletions
|
@ -565,7 +565,23 @@ x = (
|
|||
self.assertAllRaise(SyntaxError,
|
||||
"f-string: expressions nested too deeply",
|
||||
['f"{1+2:{1+2:{1+1:{1}}}}"'])
|
||||
|
||||
def create_nested_fstring(n):
|
||||
if n == 0:
|
||||
return "1+1"
|
||||
prev = create_nested_fstring(n-1)
|
||||
return f'f"{{{prev}}}"'
|
||||
|
||||
self.assertAllRaise(SyntaxError,
|
||||
"too many nested f-strings",
|
||||
[create_nested_fstring(160)])
|
||||
|
||||
def test_syntax_error_in_nested_fstring(self):
|
||||
# See gh-104016 for more information on this crash
|
||||
self.assertAllRaise(SyntaxError,
|
||||
"invalid syntax",
|
||||
['f"{1 1:' + ('{f"1:' * 199)])
|
||||
|
||||
def test_double_braces(self):
|
||||
self.assertEqual(f'{{', '{')
|
||||
self.assertEqual(f'a{{', 'a{')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue