Code

Ticket #5611: parsesql.diff

File parsesql.diff, 1.4 KB (added by Martin Kanerva, 6 years ago)

Another workaround

Line 
1Index: django/http/__init__.py
2===================================================================
3--- django/http/__init__.py     (revision 8961)
4+++ django/http/__init__.py     (working copy)
5@@ -9,6 +9,8 @@
6     from mod_python.util import parse_qsl
7 except ImportError:
8     from cgi import parse_qsl
9+# whilst being efficient, the mod_python version also breaks on certain data, so we need this for those cases
10+from cgi import parse_qsl as parse_qsl_cgi
11 
12 from django.utils.datastructures import MultiValueDict, ImmutableList
13 from django.utils.encoding import smart_str, iri_to_uri, force_unicode
14@@ -144,9 +146,14 @@
15             from django.conf import settings
16             encoding = settings.DEFAULT_CHARSET
17         self.encoding = encoding
18-        for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
19-            self.appendlist(force_unicode(key, encoding, errors='replace'),
20-                            force_unicode(value, encoding, errors='replace'))
21+        def do_parse(parse_qsl_method):
22+            for key, value in parse_qsl_method((query_string or ''), True): # keep_blank_values=True
23+                self.appendlist(force_unicode(key, encoding, errors='replace'),
24+                                force_unicode(value, encoding, errors='replace'))
25+        try:
26+            do_parse(parse_qsl)
27+        except TypeError:
28+            do_parse(parse_qsl_cgi)
29         self._mutable = mutable
30 
31     def _get_encoding(self):