From fdf182a7af85b1deeeb637ca970d31935e7c9d52 Mon Sep 17 00:00:00 2001 From: Jean Abou-Samra Date: Mon, 17 Apr 2023 20:14:42 +0200 Subject: Improve Java properties lexer (#2404) Use special lexer rules for escapes; fixes catastrophic backtracking, and highlights them too. Fixes #2356 --- pygments/lexers/configs.py | 52 ++++++---- tests/examplefiles/properties/java.properties | 13 ++- .../examplefiles/properties/java.properties.output | 110 +++++++++++++++++---- .../properties/test_escaped_space_in_value.txt | 4 +- .../properties/test_just_key_with_space.txt | 4 +- 5 files changed, 145 insertions(+), 38 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 3b1f9b4d..17842150 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -129,26 +129,42 @@ class PropertiesLexer(RegexLexer): tokens = { 'root': [ - (r'\s+', Whitespace), + # comments (r'[!#].*|/{2}.*', Comment.Single), - # search for first separator - (r'([^\\\n]|\\.)*?(?=[ \f\t=:])', Name.Attribute, "separator"), - # empty key - (r'.+?$', Name.Attribute), + # ending a comment or whitespace-only line + (r'\n', Whitespace), + # eat whitespace at the beginning of a line + (r'^[^\S\n]+', Whitespace), + # start lexing a key + default('key'), ], - 'separator': [ - # search for line continuation escape - (r'([ \f\t]*)([=:]*)([ \f\t]*)(.*(?