Commit 07efbdb4 by Mathieu Pillard Committed by Tom Christie

Fix APIClient.get() when path contains unicode arguments (#4458)

parent 80bd3b97
...@@ -79,10 +79,13 @@ class APIRequestFactory(DjangoRequestFactory): ...@@ -79,10 +79,13 @@ class APIRequestFactory(DjangoRequestFactory):
r = { r = {
'QUERY_STRING': urlencode(data or {}, doseq=True), 'QUERY_STRING': urlencode(data or {}, doseq=True),
} }
# Fix to support old behavior where you have the arguments in the url
# See #1461
if not data and '?' in path: if not data and '?' in path:
r['QUERY_STRING'] = path.split('?')[1] # Fix to support old behavior where you have the arguments in the
# url. See #1461.
query_string = force_bytes(path.split('?')[1])
if six.PY3:
query_string = query_string.decode('iso-8859-1')
r['QUERY_STRING'] = query_string
r.update(extra) r.update(extra)
return self.generic('GET', path, **r) return self.generic('GET', path, **r)
......
...@@ -245,3 +245,10 @@ class TestAPIRequestFactory(TestCase): ...@@ -245,3 +245,10 @@ class TestAPIRequestFactory(TestCase):
self.assertEqual(dict(request.GET), {'demo': ['test']}) self.assertEqual(dict(request.GET), {'demo': ['test']})
request = factory.get('/view/', {'demo': 'test'}) request = factory.get('/view/', {'demo': 'test'})
self.assertEqual(dict(request.GET), {'demo': ['test']}) self.assertEqual(dict(request.GET), {'demo': ['test']})
def test_request_factory_url_arguments_with_unicode(self):
factory = APIRequestFactory()
request = factory.get('/view/?demo=testé')
self.assertEqual(dict(request.GET), {'demo': ['testé']})
request = factory.get('/view/', {'demo': 'testé'})
self.assertEqual(dict(request.GET), {'demo': ['testé']})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment