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
2 changes: 1 addition & 1 deletion django/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def content_disposition_header(as_attachment, filename):
# characters from 0x21 to 0x7e, except 0x22 (`"`) and 0x5C (`\`) which
# can still be expressed but must be escaped with their own `\`.
# https://datatracker.ietf.org/doc/html/rfc9110#name-quoted-strings
quotable_characters = r"^[\t \x21-\x7e]*$"
quotable_characters = r"^[\t \x21-\x7e]*\Z"
if is_ascii and re.match(quotable_characters, filename):
file_expr = 'filename="{}"'.format(
filename.replace("\\", "\\\\").replace('"', r"\"")
Expand Down
2 changes: 2 additions & 0 deletions tests/utils_tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ def test_basic(self):
"attachment; filename*=utf-8''%22esp%C3%A9cimen%22%20filename",
),
((True, "some\nfile"), "attachment; filename*=utf-8''some%0Afile"),
((True, "\n"), "attachment; filename*=utf-8''%0A"),
((True, "example\n"), "attachment; filename*=utf-8''example%0A"),
)

for (is_attachment, filename), expected in tests:
Expand Down
Loading