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 @cached_property
def GET(self): def GET(self):
# Django will try and re-urldecode the string and interpret + as space; # Django will try and re-urldecode the query string and interpret + as space;
# we re-encode + here to fix this. # we re-encode it here to fix this.
return http.QueryDict( return http.QueryDict(self.message.get('query_string', ''))
self.message.get('query_string', '').replace("+", "%2b").encode("utf8"),
)
def _get_post(self): def _get_post(self):
if not hasattr(self, '_post'): if not hasattr(self, '_post'):

View File

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

View File

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