From d05095fdc8608cb47844a2594e0480c04304fb89 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 12 Sep 2026 09:12:13 +0100 Subject: Avoid excessive backtracking when parsing unterminated strings --- tests/styles/parser/tokeniser_tests.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests/styles/parser/tokeniser_tests.py') diff --git a/tests/styles/parser/tokeniser_tests.py b/tests/styles/parser/tokeniser_tests.py index 482c5b0..9fce077 100644 --- a/tests/styles/parser/tokeniser_tests.py +++ b/tests/styles/parser/tokeniser_tests.py @@ -31,14 +31,26 @@ def test_strings_are_tokenised(): assert_tokens("'Tristan'", is_token("string", "'Tristan'")) -def test_escape_sequences_in_strings_are_tokenised(): +def test_escaped_string_terminators_in_strings_are_tokenised(): assert_tokens(r"'Tristan\''", is_token("string", r"'Tristan\''")) +def test_escape_sequences_in_strings_are_tokenised(): + assert_tokens(r"'Tristan\\'", is_token("string", r"'Tristan\\'")) + + def test_unterminated_strings_are_tokenised(): assert_tokens("'Tristan", is_token("unterminated string", "'Tristan")) +def test_unterminated_strings_with_unterminated_escape_are_tokenised(): + assert_tokens("'Tristan\\", is_token("unterminated string", "'Tristan\\")) + + +def test_unterminated_strings_with_many_escape_sequences_do_not_cause_excessive_backtracking(): + assert_tokens("'" + "\\a" * 50, is_token("unterminated string", "'" + "\\a" * 50)) + + def test_arrows_are_tokenised(): assert_tokens("=>=>", is_token("symbol", "=>"), is_token("symbol", "=>")) -- cgit v1.2.3