From a38cb38e93c9635240b3ae89d78d38cf182745da Mon Sep 17 00:00:00 2001 From: jmzambon Date: Sun, 25 Sep 2022 22:56:48 +0200 Subject: [PATCH] Fix: Issues with .properties format using whitespace delimited key (#2241) Added: - support for space delimitor in every case, included multiline value - check for odd number of backslash escapes - "!" as comment start - support for escape of spaces and separators Dropped: - undocumented ";" and "//" comment start --- pygments/lexers/configs.py | 28 ++++-- tests/examplefiles/properties/java.properties | 38 ++++---- .../properties/java.properties.output | 88 ++++++++++++++----- tests/snippets/properties/test_comments.txt | 4 +- .../test_leading_whitespace_comments.txt | 2 +- .../test_space_delimited_kv_pair.txt | 3 +- 6 files changed, 114 insertions(+), 49 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 4e0e7f1282..6f61d98e41 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -128,14 +128,26 @@ class PropertiesLexer(RegexLexer): tokens = { 'root': [ - (r'^(\w+)([ \t])(\w+\s*)$', bygroups(Name.Attribute, Whitespace, String)), - (r'^\w+(\\[ \t]\w*)*$', Name.Attribute), - (r'(^ *)([#!].*)', bygroups(Whitespace, Comment)), - # More controversial comments - (r'(^ *)((?:;|//).*)', bygroups(Whitespace, Comment)), - (r'(.*?)([ \t]*)([=:])([ \t]*)(.*(?:(?<=\\)\n.*)*)', - bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), - (r'\s', Whitespace), + (r'\s+', Whitespace), + (r'[!#].*|/{2}.*', Comment.Single), + # search for first separator + (r'([^\\\n]|\\.)*?(?=[ \f\t=:])', Name.Attribute, "separator"), + # empty key + (r'.+?$', Name.Attribute), + ], + 'separator': [ + # search for line continuation escape + (r'([ \f\t]*)([=:]*)([ \f\t]*)(.*(?