summaryrefslogtreecommitdiff
path: root/django/http/request.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-07-12 19:37:59 +0200
committerClaude Paroz <claude@2xlibre.net>2014-08-19 22:30:22 +0200
commit72ad014b6aee3e8d996af4646b97228e82fc4cc1 (patch)
tree3fded795d6b688db065b7d4f18c9470bd770d4aa /django/http/request.py
parent6e5e2b0e28707d1a2cb5d7fafaba2e07bd81bdb2 (diff)
[1.7.x] Fixed #22996 -- Prevented crash with unencoded query string
Thanks Jorge Carleitao for the report and Aymeric Augustin, Tim Graham for the reviews. Backport of fa02120d36 from master.
Diffstat (limited to 'django/http/request.py')
-rw-r--r--django/http/request.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/django/http/request.py b/django/http/request.py
index 2897df7c11..aee8a0d282 100644
--- a/django/http/request.py
+++ b/django/http/request.py
@@ -313,8 +313,12 @@ class QueryDict(MultiValueDict):
self.encoding = encoding
if six.PY3:
if isinstance(query_string, bytes):
- # query_string contains URL-encoded data, a subset of ASCII.
- query_string = query_string.decode()
+ # query_string normally contains URL-encoded data, a subset of ASCII.
+ try:
+ query_string = query_string.decode(encoding)
+ except UnicodeDecodeError:
+ # ... but some user agents are misbehaving :-(
+ query_string = query_string.decode('iso-8859-1')
for key, value in parse_qsl(query_string or '',
keep_blank_values=True,
encoding=encoding):
@@ -322,8 +326,12 @@ class QueryDict(MultiValueDict):
else:
for key, value in parse_qsl(query_string or '',
keep_blank_values=True):
+ try:
+ value = value.decode(encoding)
+ except UnicodeDecodeError:
+ value = value.decode('iso-8859-1')
self.appendlist(force_text(key, encoding, errors='replace'),
- force_text(value, encoding, errors='replace'))
+ value)
self._mutable = mutable
@property