Skip to content

Commit f0b51ac

Browse files
🐛 fix unquote issue with querystring handling. (#1264)
* 🐛 fix unquote issue with querystring handling. * 🎨 fix flake8 * 📝 Add comment regarding query string handling for clarity. --------- Co-authored-by: shane <[email protected]>
1 parent 7fba630 commit f0b51ac

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

tests/tests.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,37 @@ def test_wsgi_query_string_unquoted(self):
27682768
"requestContext": {},
27692769
}
27702770
request = create_wsgi_request(event)
2771-
self.assertEqual(request["QUERY_STRING"], "a=A,B&b=C#D")
2771+
expected = "a=A%2CB&b=C%23D" # unencoded result: "a=A,B&b=C#D"
2772+
self.assertEqual(request["QUERY_STRING"], expected)
2773+
2774+
def test_wsgi_query_string_ampersand_unencoded(self):
2775+
event = {
2776+
"body": None,
2777+
"headers": {},
2778+
"pathParameters": {},
2779+
"path": "/path/path1",
2780+
"httpMethod": "GET",
2781+
"queryStringParameters": {
2782+
"test": "M&M",
2783+
},
2784+
"requestContext": {},
2785+
}
2786+
request = create_wsgi_request(event)
2787+
self.assertEqual(request["QUERY_STRING"], "test=M%26M")
2788+
2789+
def test_wsgi_query_string_with_encodechars(self):
2790+
event = {
2791+
"body": None,
2792+
"headers": {},
2793+
"pathParameters": {},
2794+
"path": "/path/path1",
2795+
"httpMethod": "GET",
2796+
"queryStringParameters": {"query": "Jane&John", "otherquery": "B", "test": "hello+m.te&how&are&you"},
2797+
"requestContext": {},
2798+
}
2799+
request = create_wsgi_request(event)
2800+
expected = "query=Jane%26John&otherquery=B&test=hello%2Bm.te%26how%26are%26you"
2801+
self.assertEqual(request["QUERY_STRING"], expected)
27722802

27732803

27742804
if __name__ == "__main__":

zappa/wsgi.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ def create_wsgi_request(
3636
# we have to check for the existence of one and then fall back to the
3737
# other.
3838

39+
# Assumes that the lambda event provides the unencoded string as
40+
# the value in "queryStringParameters"/"multiValueQueryStringParameters"
41+
# The QUERY_STRING value provided to WSGI expects the query string to be properly urlencoded.
42+
# See https://github.com/zappa/Zappa/issues/1227 for discussion of this behavior.
3943
if "multiValueQueryStringParameters" in event_info:
4044
query = event_info["multiValueQueryStringParameters"]
4145
query_string = urlencode(query, doseq=True) if query else ""
4246
else:
4347
query = event_info.get("queryStringParameters", {})
4448
query_string = urlencode(query) if query else ""
45-
query_string = unquote(query_string)
4649

4750
if context_header_mappings:
4851
for key, value in context_header_mappings.items():

0 commit comments

Comments
 (0)