summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mimeparse.py3
-rw-r--r--testdata.json1
2 files changed, 3 insertions, 1 deletions
diff --git a/mimeparse.py b/mimeparse.py
index 7f4aa3c..91b28b8 100644
--- a/mimeparse.py
+++ b/mimeparse.py
@@ -72,8 +72,9 @@ def parse_media_range(range):
necessary.
"""
(type, subtype, params) = parse_mime_type(range)
+ params.setdefault('q', params.pop('Q', None)) # q is case insensitive
try:
- if not params.get('q') or not 0 <= float(params['q']) <= 1:
+ if not params['q'] or not 0 <= float(params['q']) <= 1:
params['q'] = '1'
except ValueError: # from float()
params['q'] = '1'
diff --git a/testdata.json b/testdata.json
index ab7693c..4f0a648 100644
--- a/testdata.json
+++ b/testdata.json
@@ -9,6 +9,7 @@
["application/xml ; q=2;b=other",["application", "xml", {"q": "1", "b":"other"}]],
["application/xml ; q=0",["application", "xml", {"q": "0"}]],
["application/xml ; q=foo", ["application", "xml", {"q": "1"}]],
+ ["application/xml ; Q=0.6", ["application", "xml", {"q": "0.6"}]],
[" *; q=.2",["*", "*", {"q": ".2"}]]
],