Skip to content

Commit 0eb6fa3

Browse files
committed
httpserver.py: remove the now deprecated werkzeug.urls.url_decode call
1 parent 91270ac commit 0eb6fa3

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

pytest_httpserver/httpserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import threading
77
import time
8+
import urllib.parse
89
from collections import defaultdict
910
from contextlib import contextmanager
1011
from contextlib import suppress
@@ -22,7 +23,6 @@
2223
from typing import Tuple
2324
from typing import Union
2425

25-
import werkzeug.urls
2626
from werkzeug.datastructures import MultiDict
2727
from werkzeug.http import parse_authorization_header
2828
from werkzeug.serving import make_server
@@ -216,7 +216,7 @@ def __init__(self, query_dict: Union[Mapping, MultiDict]):
216216
self.query_dict = query_dict
217217

218218
def get_comparing_values(self, request_query_string: bytes) -> tuple:
219-
query = werkzeug.urls.url_decode(request_query_string)
219+
query = MultiDict(urllib.parse.parse_qsl(request_query_string.decode("utf-8")))
220220
if isinstance(self.query_dict, MultiDict):
221221
return (query, self.query_dict)
222222
else:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fix Werkzeug deprecation warning about ``werkzeug.urls.url_decode`` call. This
5+
call has been changed to ``urllib.parse.parse_qsl`` in the implementation.
6+
This fix should not introduce any functional change for the users.

tests/test_parse_qs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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)

tests/test_release.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_sdist_contents(build: Build, version: str):
205205
"test_oneshot.py",
206206
"test_ordered.py",
207207
"test_permanent.py",
208+
"test_parse_qs.py",
208209
"test_port_changing.py",
209210
"test_querymatcher.py",
210211
"test_querystring.py",

0 commit comments

Comments
 (0)