Skip to content

Commit adda0c1

Browse files
committed
fix handling of latin1-encoded utf-8 path from WSGI server
1 parent 930f3ff commit adda0c1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pigwig/pigwig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __call__(self, environ: dict, start_response: Callable) -> Iterable[bytes]:
155155
def build_request(self, environ: dict) -> tuple[Request, Exception | None]:
156156
""" builds :class:`.Response` objects. for internal use. """
157157
method = environ['REQUEST_METHOD']
158-
path = environ['PATH_INFO']
158+
path = environ['PATH_INFO'].encode('latin-1').decode('utf-8') # https://github.com/python/cpython/issues/60883
159159
query: Mapping[str, list[str] | str] = {}
160160
headers = HTTPHeaders()
161161
cookies = http.cookies.SimpleCookie()

pigwig/tests/test_pigwig.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ def test_build_request(self):
1313
app = PigWig([])
1414
environ = {
1515
'REQUEST_METHOD': 'test method',
16-
'PATH_INFO': 'test path?a=1&b=2&b=3',
16+
'PATH_INFO': 'test path?a=1&b=2&b=3&c=\xe4\xbd\xa0\xe5\xa5\xbd',
1717
'HTTP_COOKIE': 'a=1; a="2"',
1818
'wsgi.input': None,
1919
}
2020
req, err = app.build_request(environ)
2121
self.assertIsNone(err)
2222
self.assertEqual(req.method, 'test method')
23-
self.assertEqual(req.path, 'test path?a=1&b=2&b=3')
23+
self.assertEqual(req.path, 'test path?a=1&b=2&b=3&c=你好')
2424
self.assertEqual(req.query, {})
2525
self.assertEqual(req.cookies['a'].value, '2')
2626

27-
environ['QUERY_STRING'] = 'a=1&b=2&b=3'
27+
environ['QUERY_STRING'] = 'a=1&b=2&b=3&c=你好'
2828
req, err = app.build_request(environ)
2929
self.assertIsNone(err)
30-
self.assertEqual(req.query, {'a': '1', 'b': ['2', '3']})
30+
self.assertEqual(req.query, {'a': '1', 'b': ['2', '3'], 'c': '你好'})
3131

3232
environ['CONTENT_TYPE'] = 'application/json; charset=utf8'
3333
environ['wsgi.input'] = io.BytesIO(b'{"a": 1, "a": NaN}')

0 commit comments

Comments
 (0)