Skip to content

Commit 64a64e3

Browse files
committed
Handle q parameter name case insensitively
https://tools.ietf.org/html/rfc7231#section-5.3.1
1 parent 7d3bf00 commit 64a64e3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

mimeparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def parse_media_range(range):
7272
necessary.
7373
"""
7474
(type, subtype, params) = parse_mime_type(range)
75+
params.setdefault('q', params.pop('Q', None)) # q is case insensitive
7576
try:
76-
if not params.get('q') or not 0 <= float(params['q']) <= 1:
77+
if not params['q'] or not 0 <= float(params['q']) <= 1:
7778
params['q'] = '1'
7879
except ValueError: # from float()
7980
params['q'] = '1'

testdata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
["application/xml ; q=2;b=other",["application", "xml", {"q": "1", "b":"other"}]],
1010
["application/xml ; q=0",["application", "xml", {"q": "0"}]],
1111
["application/xml ; q=foo", ["application", "xml", {"q": "1"}]],
12+
["application/xml ; Q=0.6", ["application", "xml", {"q": "0.6"}]],
1213
[" *; q=.2",["*", "*", {"q": ".2"}]]
1314
],
1415

0 commit comments

Comments
 (0)