summaryrefslogtreecommitdiff
path: root/Lib/test/test_patma.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_patma.py')
-rw-r--r--Lib/test/test_patma.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_patma.py b/Lib/test/test_patma.py
index aa18e29e22..b8444822c8 100644
--- a/Lib/test/test_patma.py
+++ b/Lib/test/test_patma.py
@@ -3138,6 +3138,27 @@ class TestTracing(unittest.TestCase):
self.assertListEqual(self._trace(f, "go x"), [1, 2, 3])
self.assertListEqual(self._trace(f, "spam"), [1, 2, 3])
+ def test_parser_deeply_nested_patterns(self):
+ # Deeply nested patterns can cause exponential backtracking when parsing.
+ # See gh-93671 for more information.
+
+ levels = 100
+
+ patterns = [
+ "A" + "(" * levels + ")" * levels,
+ "{1:" * levels + "1" + "}" * levels,
+ "[" * levels + "1" + "]" * levels,
+ ]
+
+ for pattern in patterns:
+ with self.subTest(pattern):
+ code = inspect.cleandoc("""
+ match None:
+ case {}:
+ pass
+ """.format(pattern))
+ compile(code, "<string>", "exec")
+
if __name__ == "__main__":
"""