Skip to content

BugFix: Asgi Path Param Encoding change to utf-8 #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions azure/functions/_http_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def __init__(self,
# 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))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_http_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
WsgiResponse,
WsgiMiddleware
)
from azure.functions._http_asgi import AsgiRequest


class WsgiException(Exception):
Expand Down Expand Up @@ -211,6 +212,18 @@ def test_middleware_wrapper(self):
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, '/Pippi Långstrump')

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, '/Pippi LÃ¥ngstrump')

def _generate_func_request(
self,
method="POST",
Expand Down