BugFix: Asgi Path Param Encoding change to utf-8 (#208)
* fix: third party web app, changing request path encoding to utf-8 * fix * style fix * ignore * fix * add tests * fix * Update tests/test_http_wsgi.py Co-authored-by: Fredrik Erlandsson <fredrik.e@gmail.com> * Update tests/test_http_wsgi.py Co-authored-by: Fredrik Erlandsson <fredrik.e@gmail.com> * Update test_http_wsgi.py --------- Co-authored-by: Fredrik Erlandsson <fredrik.e@gmail.com>
This commit is contained in:
Родитель
9574a5ce01
Коммит
5a9360bab7
|
@ -29,8 +29,11 @@ class WsgiRequest:
|
|||
# Implement interfaces for PEP 3333 environ
|
||||
self.request_method = getattr(func_req, 'method', None)
|
||||
self.script_name = ''
|
||||
self.path_info = unquote_to_bytes(
|
||||
getattr(url, 'path', None)).decode('latin-1') # type: ignore
|
||||
self.path_info = (
|
||||
unquote_to_bytes(getattr(url, 'path', None)) # type: ignore
|
||||
.decode('latin-1' if type(self) is WsgiRequest else 'utf-8')
|
||||
)
|
||||
|
||||
self.query_string = getattr(url, 'query', None)
|
||||
self.content_type = self._lowercased_headers.get('content-type')
|
||||
self.content_length = str(len(func_req_body))
|
||||
|
|
|
@ -14,6 +14,7 @@ from azure.functions._http_wsgi import (
|
|||
WsgiResponse,
|
||||
WsgiMiddleware
|
||||
)
|
||||
from azure.functions._http_asgi import AsgiRequest
|
||||
|
||||
|
||||
class WsgiException(Exception):
|
||||
|
@ -211,6 +212,18 @@ class TestHttpWsgi(unittest.TestCase):
|
|||
self.assertEqual(func_response.status_code, 200)
|
||||
self.assertEqual(func_response.get_body(), b'sample string')
|
||||
|
||||
def test_path_encoding_utf8(self):
|
||||
url = 'http://example.com/Pippi%20L%C3%A5ngstrump'
|
||||
request = AsgiRequest(self._generate_func_request(url=url))
|
||||
|
||||
self.assertEqual(request.path_info, u'/Pippi L\u00e5ngstrump')
|
||||
|
||||
def test_path_encoding_latin1(self):
|
||||
url = 'http://example.com/Pippi%20L%C3%A5ngstrump'
|
||||
request = WsgiRequest(self._generate_func_request(url=url))
|
||||
|
||||
self.assertEqual(request.path_info, u'/Pippi L\u00c3\u00a5ngstrump')
|
||||
|
||||
def _generate_func_request(
|
||||
self,
|
||||
method="POST",
|
||||
|
|
Загрузка…
Ссылка в новой задаче