More robust mime type parsing

Closes #344
This commit is contained in:
Jakub Roztocil 2016-02-28 20:12:16 +08:00
parent e385ed6a99
commit 0f8d04b4df
2 changed files with 3 additions and 2 deletions

View File

@ -65,11 +65,11 @@ class ColorFormatter(FormatterPlugin):
def get_lexer(mime):
mime_types, lexer_names = [mime], []
type_, subtype = mime.split('/')
type_, subtype = mime.split('/', 1)
if '+' not in subtype:
lexer_names.append(subtype)
else:
subtype_name, subtype_suffix = subtype.split('+')
subtype_name, subtype_suffix = subtype.split('+', 1)
lexer_names.extend([subtype_name, subtype_suffix])
mime_types.extend([
'%s/%s' % (type_, subtype_name),

View File

@ -39,6 +39,7 @@ class TestColors:
'foo/bar+json',
'foo/json-foo',
'foo/x-json',
'application/vnd.comverge.grid+hal+json',
])
def test_get_lexer(self, mime):
lexer = get_lexer(mime)