diff options
author | Tim Hatch <tim@timhatch.com> | 2016-05-31 22:17:14 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2016-05-31 22:17:14 -0700 |
commit | 9df6f911209b5ef4ae3d3521048844afebe6f994 (patch) | |
tree | b6f94d242d400377eaea5495bfa7dffd3ad676a5 | |
parent | 11f5df043d36049fb066e41178c31c2e64410c7b (diff) | |
download | pygments-9df6f911209b5ef4ae3d3521048844afebe6f994.tar.gz |
Robustify json-object against unexpected '}'
-rw-r--r-- | pygments/lexers/data.py | 6 | ||||
-rw-r--r-- | tests/test_data.py | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index fbc25bf2..4c39db64 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -476,7 +476,7 @@ class JsonLexer(RegexLexer): # comma terminates the attribute but expects more (r',', Punctuation, '#pop'), # a closing bracket terminates the entire object, so pop twice - (r'\}', Punctuation, ('#pop', '#pop')), + (r'\}', Punctuation, '#pop:2'), ], # a json object - { attr, attr, ... } @@ -526,6 +526,10 @@ class JsonBareObjectLexer(JsonLexer): (r'\}', Error), include('objectvalue'), ], + 'objectattribute': [ + (r'\}', Error), + inherit, + ], } diff --git a/tests/test_data.py b/tests/test_data.py index ea4c9be6..be371419 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -85,3 +85,16 @@ class JsonBareObjectTest(unittest.TestCase): (Token.Text, '\n'), ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testClosingCurlyInValue(self): + fragment = '"": ""}\n' + tokens = [ + (Token.Name.Tag, '""'), + (Token.Punctuation, ':'), + (Token.Text, ' '), + (Token.Literal.String.Double, '""'), + (Token.Error, '}'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + |