diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-11-03 21:26:59 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-11-03 21:28:33 +0100 |
| commit | 973f539ab83bb46645f2f711190735c66a246797 (patch) | |
| tree | c76362c3ea3589256608b44e79ce3c85d480213c /django | |
| parent | 3e98d98b69e67f2f72055e4b3204d0486eaeff50 (diff) | |
Fixed #15152 -- Avoided crash of CommonMiddleware on broken querystring
Diffstat (limited to 'django')
| -rw-r--r-- | django/middleware/common.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/middleware/common.py b/django/middleware/common.py index 6fbbf43044..ccc9fbfaad 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -6,6 +6,7 @@ from django.conf import settings from django import http from django.core.mail import mail_managers from django.utils.http import urlquote +from django.utils import six from django.core import urlresolvers @@ -87,7 +88,17 @@ class CommonMiddleware(object): else: newurl = urlquote(new_url[1]) if request.META.get('QUERY_STRING', ''): - newurl += '?' + request.META['QUERY_STRING'] + if six.PY3: + newurl += '?' + request.META['QUERY_STRING'] + else: + # `query_string` is a bytestring. Appending it to the unicode + # string `newurl` will fail if it isn't ASCII-only. This isn't + # allowed; only broken software generates such query strings. + # Better drop the invalid query string than crash (#15152). + try: + newurl += '?' + request.META['QUERY_STRING'].decode() + except UnicodeDecodeError: + pass return http.HttpResponsePermanentRedirect(newurl) def process_response(self, request, response): |
