From 07efbdb45e5c7ef70249e985b3c1ef1cead455ba Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Fri, 2 Sep 2016 18:00:03 +0200 Subject: [PATCH] Fix APIClient.get() when path contains unicode arguments (#4458) --- rest_framework/test.py | 9 ++++++--- tests/test_testing.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rest_framework/test.py b/rest_framework/test.py index 3ba4059a9..fd9f6ab13 100644 --- a/rest_framework/test.py +++ b/rest_framework/test.py @@ -79,10 +79,13 @@ class APIRequestFactory(DjangoRequestFactory): r = { '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: - 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) return self.generic('GET', path, **r) diff --git a/tests/test_testing.py b/tests/test_testing.py index 3adcc55f8..6683ae6ed 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -245,3 +245,10 @@ class TestAPIRequestFactory(TestCase): self.assertEqual(dict(request.GET), {'demo': ['test']}) request = factory.get('/view/', {'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é']})