Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mimeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ def parse_mime_type(mime_type):
if full_type == '*':
full_type = '*/*'

if '/' not in full_type:
type_parts = full_type.split('/') if '/' in full_type else None
if not type_parts or len(type_parts) > 2:
raise MimeTypeParseException("Can't parse type \"{}\"".format(full_type))

(type, subtype) = full_type.split('/')
(type, subtype) = type_parts

return (type.strip(), subtype.strip(), params)

Expand Down
3 changes: 2 additions & 1 deletion testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"parse_mime_type": [
["application/xhtml;q=0.5", ["application", "xhtml", {"q": "0.5"}]],
["application/xhtml;q=0.5;ver=1.2", ["application", "xhtml", {"q": "0.5", "ver": "1.2"}]],
["text", null]
["text", null],
["text/something/invalid", null]
]
}