mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:29:23 +08:00
content_disposition neutralized quotes and backslashes in the ASCII filename= fallback but left C0 control characters untouched. A filename containing CR/LF produced a header value with a raw newline — a malformed header / response-splitting shape that the ASGI server rejects (500). Strip control chars like the sibling partners.helpers.safe_filename already does. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
25 lines
812 B
Python
25 lines
812 B
Python
"""Content-Disposition header values must stay single-line.
|
|
|
|
The ASCII fallback neutralized quotes and backslashes but left C0 control
|
|
characters (notably CR/LF) untouched, so a filename containing a newline
|
|
produced a header value with a raw ``\n`` in it — a malformed header /
|
|
response-splitting shape that the ASGI server rejects (500).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from deeptutor.api.utils.http_headers import content_disposition
|
|
|
|
|
|
def test_control_characters_are_stripped_from_ascii_fallback() -> None:
|
|
header = content_disposition("a\r\nb.pdf")
|
|
|
|
assert "\n" not in header
|
|
assert "\r" not in header
|
|
|
|
|
|
def test_plain_filename_is_unchanged() -> None:
|
|
header = content_disposition("report.pdf")
|
|
|
|
assert header == "inline; filename=\"report.pdf\"; filename*=UTF-8''report.pdf"
|