e506c89304
* ➖ deprecate None value support for app name * 🚨 cleanup linter issues across the codebase
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
import pytest
|
|
|
|
from sanic import headers
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"input, expected",
|
|
[
|
|
("text/plain", ("text/plain", {})),
|
|
("text/vnd.just.made.this.up ; ", ("text/vnd.just.made.this.up", {})),
|
|
(
|
|
"text/plain;charset=us-ascii",
|
|
("text/plain", {"charset": "us-ascii"}),
|
|
),
|
|
(
|
|
'text/plain ; charset="us-ascii"',
|
|
("text/plain", {"charset": "us-ascii"}),
|
|
),
|
|
(
|
|
'text/plain ; charset="us-ascii"; another=opt',
|
|
("text/plain", {"charset": "us-ascii", "another": "opt"}),
|
|
),
|
|
(
|
|
'attachment; filename="silly.txt"',
|
|
("attachment", {"filename": "silly.txt"}),
|
|
),
|
|
(
|
|
'attachment; filename="strange;name"',
|
|
("attachment", {"filename": "strange;name"}),
|
|
),
|
|
(
|
|
'attachment; filename="strange;name";size=123;',
|
|
("attachment", {"filename": "strange;name", "size": "123"}),
|
|
),
|
|
(
|
|
'form-data; name="files"; filename="fo\\"o;bar\\"',
|
|
("form-data", {"name": "files", "filename": 'fo"o;bar\\'})
|
|
# cgi.parse_header:
|
|
# ('form-data', {'name': 'files', 'filename': 'fo"o;bar\\'})
|
|
# werkzeug.parse_options_header:
|
|
# ('form-data', {'name': 'files', 'filename': '"fo\\"o', 'bar\\"': None})
|
|
),
|
|
# <input type=file name="foo";bar\"> with Unicode filename!
|
|
(
|
|
# Chrome:
|
|
# Content-Disposition: form-data; name="foo%22;bar\"; filename="😀"
|
|
'form-data; name="foo%22;bar\\"; filename="😀"',
|
|
("form-data", {"name": 'foo";bar\\', "filename": "😀"})
|
|
# cgi: ('form-data', {'name': 'foo%22;bar"; filename="😀'})
|
|
# werkzeug: ('form-data', {'name': 'foo%22;bar"; filename='})
|
|
),
|
|
(
|
|
# Firefox:
|
|
# Content-Disposition: form-data; name="foo\";bar\"; filename="😀"
|
|
'form-data; name="foo\\";bar\\"; filename="😀"',
|
|
("form-data", {"name": 'foo";bar\\', "filename": "😀"})
|
|
# cgi: ('form-data', {'name': 'foo";bar"; filename="😀'})
|
|
# werkzeug: ('form-data', {'name': 'foo";bar"; filename='})
|
|
),
|
|
],
|
|
)
|
|
def test_parse_headers(input, expected):
|
|
assert headers.parse_content_header(input) == expected
|