Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lowercase the parsed options names #2442

Merged
merged 1 commit into from
Jul 4, 2022
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
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Version 2.2.0
- Fix compatibility with Python 3.11 by ensuring that ``end_lineno``
and ``end_col_offset`` are present on AST nodes. :issue:`2425`
- Add a new faster matching router based on a state
machine. :pr:`2433`.
machine. :pr:`2433`
- Names within options headers are always converted to lowercase. This
matches :rfc:`6266` that the case is not relevant. :issue:`2442`


Version 2.1.2
Expand Down
5 changes: 4 additions & 1 deletion src/werkzeug/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ def parse_options_header(

:param value: The header value to parse.

.. versionchanged:: 2.2
Option names are always converted to lowercase.

.. versionchanged:: 2.1
The ``multiple`` parameter is deprecated and will be removed in
Werkzeug 2.2.
Expand Down Expand Up @@ -440,7 +443,7 @@ def parse_options_header(
if not encoding:
encoding = continued_encoding
continued_encoding = encoding
option = unquote_header_value(option)
option = unquote_header_value(option).lower()

if option_value is not None:
option_value = unquote_header_value(option_value, option == "filename")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ def test_parse_options_header_broken_values(self):
assert http.parse_options_header(" , a ") == ("", {})
assert http.parse_options_header(" ; a ") == ("", {})

def test_parse_options_header_case_insensitive(self):
_, options = http.parse_options_header(r'something; fileName="File.ext"')
assert options["filename"] == "File.ext"

def test_dump_options_header(self):
assert http.dump_options_header("foo", {"bar": 42}) == "foo; bar=42"
assert http.dump_options_header("foo", {"bar": 42, "fizz": None}) in (
Expand Down