Skip to content

Commit

Permalink
BugFix: Asgi Path Param Encoding change to utf-8 (Azure#208)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update tests/test_http_wsgi.py

Co-authored-by: Fredrik Erlandsson <[email protected]>

* Update test_http_wsgi.py

---------

Co-authored-by: Fredrik Erlandsson <[email protected]>
  • Loading branch information
YunchuWang and fredrike authored Apr 12, 2024
1 parent 9574a5c commit 5a9360b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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, 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",
Expand Down

0 comments on commit 5a9360b

Please sign in to comment.