mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #15152 -- Avoided crash of CommonMiddleware on broken querystring
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user