|
| 1 | +import urllib.parse |
| 2 | +from typing import List |
| 3 | +from typing import Tuple |
| 4 | + |
| 5 | +import pytest |
| 6 | +import werkzeug.urls |
| 7 | +from werkzeug.datastructures import MultiDict |
| 8 | + |
| 9 | +parse_qsl_semicolon_cases = [ |
| 10 | + ("&", []), |
| 11 | + ("&&", []), |
| 12 | + ("&a=b", [("a", "b")]), |
| 13 | + ("a=a+b&b=b+c", [("a", "a b"), ("b", "b c")]), |
| 14 | + ("a=1&a=2", [("a", "1"), ("a", "2")]), |
| 15 | + ("a=", [("a", "")]), |
| 16 | + ("a=foo bar&b=bar foo", [("a", "foo bar"), ("b", "bar foo")]), |
| 17 | + ("a=foo%20bar&b=bar%20foo", [("a", "foo bar"), ("b", "bar foo")]), |
| 18 | + ("a=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D", [("a", " !\"#$%&'()*+,/:;=?@[]")]), |
| 19 | +] |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.parametrize("qs,expected", parse_qsl_semicolon_cases) |
| 23 | +def test_qsl(qs: str, expected: List[Tuple[bytes, bytes]]): |
| 24 | + assert urllib.parse.parse_qsl(qs, keep_blank_values=True) == expected |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.skip(reason="skipped to avoid werkzeug warnings") |
| 28 | +@pytest.mark.parametrize("qs,expected", parse_qsl_semicolon_cases) |
| 29 | +def test_qsl_werkzeug(qs: str, expected: List[Tuple[bytes, bytes]]): |
| 30 | + assert werkzeug.urls.url_decode(qs) == MultiDict(expected) |
0 commit comments