diff --git a/httpie/output/lexers/json.py b/httpie/output/lexers/json.py index d26e522f30..686f02a39c 100644 --- a/httpie/output/lexers/json.py +++ b/httpie/output/lexers/json.py @@ -5,6 +5,7 @@ from pygments.token import Token PREFIX_TOKEN = Token.Error +# Original prefix regex - matches anything except {, [, " PREFIX_REGEX = r'[^{\["]+' @@ -20,9 +21,11 @@ class EnhancedJsonLexer(RegexLexer): tokens = { 'root': [ # Eventual non-JSON data prefix followed by actual JSON body. - # FIX: data prefix + number (integer or float) is not correctly handled. + # Handle numbers specially: match prefix that doesn't end with digits + # when a number follows (to avoid matching numbers in prefixes like while(1);) ( - fr'({PREFIX_REGEX})' + r'((?:[{\["]|true|false|null).+)', + r'([^{\["]+?)(?=[{\["tfn]|(?