Fixed #210: Fix query string to be bytes and not decoded

This commit is contained in:
Andrew Godwin 2016-06-22 09:44:10 -07:00
parent 274feeb42f
commit e890c48f3f
3 changed files with 6 additions and 11 deletions

View File

@ -135,11 +135,9 @@ class AsgiRequest(http.HttpRequest):
@cached_property
def GET(self):
# Django will try and re-urldecode the string and interpret + as space;
# we re-encode + here to fix this.
return http.QueryDict(
self.message.get('query_string', '').replace("+", "%2b").encode("utf8"),
)
# Django will try and re-urldecode the query string and interpret + as space;
# we re-encode it here to fix this.
return http.QueryDict(self.message.get('query_string', ''))
def _get_post(self):
if not hasattr(self, '_post'):

View File

@ -46,7 +46,7 @@ class RequestTests(ChannelTestCase):
"http_version": "1.1",
"method": "GET",
"path": "/test2/",
"query_string": "x=1&y=foo bar+baz",
"query_string": b"x=1&y=%26foo+bar%2Bbaz",
"headers": {
"host": b"example.com",
"cookie": b"test-time=1448995585123; test-value=yeah",
@ -65,7 +65,7 @@ class RequestTests(ChannelTestCase):
self.assertEqual(request.META["SERVER_NAME"], "10.0.0.2")
self.assertEqual(request.META["SERVER_PORT"], 80)
self.assertEqual(request.GET["x"], "1")
self.assertEqual(request.GET["y"], "foo bar+baz")
self.assertEqual(request.GET["y"], "&foo bar+baz")
self.assertEqual(request.COOKIES["test-time"], "1448995585123")
self.assertEqual(request.COOKIES["test-value"], "yeah")
self.assertFalse(request.POST)

View File

@ -526,10 +526,7 @@ Keys:
* ``path``: Unicode string HTTP path from URL, with percent escapes decoded
and UTF8 byte sequences decoded into characters.
* ``query_string``: Unicode string URL portion after the ``?``, already
url-decoded, like ``path``. Optional, default is ``""``. ``+`` characters in
this portion should be interpreted by the application to be literal pluses,
not spaces.
* ``query_string``: Byte string URL portion after the ``?``, not url-decoded.
* ``root_path``: Unicode string that indicates the root path this application
is mounted at; same as ``SCRIPT_NAME`` in WSGI. Optional, defaults