Ticket #19075: 19075-1.diff

File 19075-1.diff, 1.6 KB (added by Claude Paroz, 12 years ago)

Properly decode query string

  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index ecb3912..3a9c57d 100644
    a b class QueryDict(MultiValueDict):  
    392392                                        encoding=encoding):
    393393                self.appendlist(key, value)
    394394        else:
    395             for key, value in parse_qsl(query_string or '',
     395            for key, value in parse_qsl(force_bytes(query_string) if query_string else '',
    396396                                        keep_blank_values=True):
    397397                self.appendlist(force_text(key, encoding, errors='replace'),
    398398                                force_text(value, encoding, errors='replace'))
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index 4c6aed1..93f82ba 100644
    a b class QueryDictTests(unittest.TestCase):  
    9595        self.assertEqual(q.urlencode(), 'next=%2Ft%C3%ABst%26key%2F')
    9696        self.assertEqual(q.urlencode(safe='/'), 'next=/t%C3%ABst%26key/')
    9797
     98    def test_querystring_decode(self):
     99        q = QueryDict(str('q=%D1%82%D0%B5%D1%81%D1%82'))
     100        self.assertEqual(q['q'], "тест")
     101        # With Python 2, unicode query string should also be properly decoded (#19075)
     102        q = QueryDict('q=%D1%82%D0%B5%D1%81%D1%82')
     103        self.assertEqual(q['q'], "тест")
     104
    98105    def test_mutable_copy(self):
    99106        """A copy of a QueryDict is mutable."""
    100107        q = QueryDict(str('')).copy()
Back to Top