summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorjx124 <64946984+jx124@users.noreply.github.com>2023-05-01 19:15:47 (GMT)
committerGitHub <noreply@github.com>2023-05-01 19:15:47 (GMT)
commit5078eedc5b18f0d208af6e30f60b33419132d1b6 (patch)
tree99d57cfef95a7e9fdefa3cfc39887d6c1f3b0658 /Lib
parent2d526cd32fe8b286aae38956648e508070729f8f (diff)
downloadcpython-5078eedc5b18f0d208af6e30f60b33419132d1b6.zip
cpython-5078eedc5b18f0d208af6e30f60b33419132d1b6.tar.gz
cpython-5078eedc5b18f0d208af6e30f60b33419132d1b6.tar.bz2
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>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_fstring.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 5e94c99..5c5176d 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -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{')