diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index 0d9bd12e2f..70797ea2eb 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -174,6 +174,7 @@ def get_lexer( for name in lexer_names: try: lexer = pygments.lexers.get_lexer_by_name(name) + break except ClassNotFound: pass diff --git a/tests/test_output.py b/tests/test_output.py index 2242177dbc..ad2075d899 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -235,6 +235,10 @@ class TestColors: ('foo/json-foo', False, None, 'JSON'), ('foo/x-json', False, None, 'JSON'), ('application/vnd.comverge.grid+hal+json', False, None, 'JSON'), + # When both the subtype name and the `+`-suffix resolve to a lexer, + # the name must win (it is tried first). Previously the lexer-name + # loop had no break, so the last match -- the suffix -- won instead. + ('application/yaml+python', False, None, 'YAML'), ('text/plain', True, '{}', 'JSON'), ('text/plain', True, 'foo', 'Text only'), ]