diff options
author | Georg Brandl <georg@python.org> | 2020-09-17 08:59:46 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2020-09-17 09:00:50 +0200 |
commit | 4587a7e80145d79ef49de1c15ca58a1a13cc9987 (patch) | |
tree | d34e12c188e525d72980d383505db85e95e1ea88 | |
parent | 8305c649ebcf55ab1f66586651da5c4888ab78e2 (diff) | |
download | pygments-git-4587a7e80145d79ef49de1c15ca58a1a13cc9987.tar.gz |
fix regression in JSON lexer, bump to 2.7.12.7.1
Fixes #1544
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | pygments/__init__.py | 2 | ||||
-rw-r--r-- | pygments/lexers/data.py | 4 | ||||
-rw-r--r-- | tests/test_data.py | 19 |
4 files changed, 20 insertions, 12 deletions
@@ -7,9 +7,12 @@ pull request numbers to the requests at <https://github.com/pygments/pygments/pulls>. -Version 2.8.0 +Version 2.7.1 ------------- -(not released yet) +(released September 16, 2020) + +- Fixed a regression in the JSON lexer (#1544) + Version 2.7.0 ------------- diff --git a/pygments/__init__.py b/pygments/__init__.py index da9ebeb1..9204a4cc 100644 --- a/pygments/__init__.py +++ b/pygments/__init__.py @@ -28,7 +28,7 @@ import sys from io import StringIO, BytesIO -__version__ = '2.7.0' +__version__ = '2.7.1' __docformat__ = 'restructuredtext' __all__ = ['lex', 'format', 'highlight'] diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index 937dfda1..fa05b10c 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -471,7 +471,7 @@ class JsonLexer(RegexLexer): '%(exp_part)s|%(frac_part)s)') % vars(), Number.Float), (int_part, Number.Integer), - (r'"(\\(["\\/bfnrt]|u[a-fA-F0-9]]{4})|[^\\"])*"', String.Double), + (r'"(\\(["\\/bfnrt]|u[a-fA-F0-9]{4})|[^\\"])*"', String.Double), ], @@ -488,7 +488,7 @@ class JsonLexer(RegexLexer): # a json object - { attr, attr, ... } 'objectvalue': [ include('whitespace'), - (r'"(\\(["\\/bfnrt]|u[a-fA-F0-9]]{4})|[^\\"])*"', Name.Tag, 'objectattribute'), + (r'"(\\(["\\/bfnrt]|u[a-fA-F0-9]{4})|[^\\"])*"', Name.Tag, 'objectattribute'), (r'\}', Punctuation, '#pop'), ], diff --git a/tests/test_data.py b/tests/test_data.py index 22d4ee79..db094d52 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -29,7 +29,7 @@ def lexer_yaml(): def test_basic_json(lexer_json): - fragment = '{"foo": "bar", "foo2": [1, 2, 3]}\n' + fragment = '{"foo": "bar", "foo2": [1, 2, 3], "\\u0123": "\\u0123"}\n' tokens = [ (Token.Punctuation, '{'), (Token.Name.Tag, '"foo"'), @@ -50,6 +50,12 @@ def test_basic_json(lexer_json): (Token.Text, ' '), (Token.Literal.Number.Integer, '3'), (Token.Punctuation, ']'), + (Token.Punctuation, ','), + (Token.Text, ' '), + (Token.Name.Tag, '"\\u0123"'), + (Token.Punctuation, ':'), + (Token.Text, ' '), + (Token.Literal.String.Double, '"\\u0123"'), (Token.Punctuation, '}'), (Token.Text, '\n'), ] @@ -61,8 +67,8 @@ def test_json_escape_backtracking(lexer_json): # to fall into catastrophic backtracking. unfortunately, if it's broken # this test will hang and that's how we know it's broken :( fragment = r'{"\u00D0000\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\63CD' - tokens = ( - [(Token.Punctuation, '{'), + tokens = [ + (Token.Punctuation, '{'), (Token.Error, r'"'), (Token.Error, '\\'), (Token.Error, r'u'), @@ -72,14 +78,13 @@ def test_json_escape_backtracking(lexer_json): (Token.Error, r'0'), (Token.Error, r'0'), (Token.Error, r'0'), - (Token.Error, r'0')] - + [(Token.Error, '\\')] * 178 - + [(Token.Error, r'6'), + (Token.Error, r'0') + ] + [(Token.Error, '\\')] * 178 + [ + (Token.Error, r'6'), (Token.Error, r'3'), (Token.Error, r'C'), (Token.Error, r'D'), (Token.Text, '\n')] - ) assert list(lexer_json.get_tokens(fragment)) == tokens |