diff --git a/django/middleware/common.py b/django/middleware/common.py
index 92f8cb3..2507379 100644
a
|
b
|
from django.conf import settings
|
7 | 7 | from django.core.mail import mail_managers |
8 | 8 | from django.core import urlresolvers |
9 | 9 | from django import http |
| 10 | from django.utils.encoding import force_text |
10 | 11 | from django.utils.http import urlquote |
11 | 12 | from django.utils import six |
12 | 13 | |
… |
… |
class BrokenLinkEmailsMiddleware(object):
|
140 | 141 | if response.status_code == 404 and not settings.DEBUG: |
141 | 142 | domain = request.get_host() |
142 | 143 | path = request.get_full_path() |
143 | | referer = request.META.get('HTTP_REFERER', '') |
| 144 | referer = force_text(request.META.get('HTTP_REFERER', ''), errors='replace') |
144 | 145 | is_internal = self.is_internal_request(domain, referer) |
145 | 146 | is_not_search_engine = '?' not in referer |
146 | 147 | is_ignorable = self.is_ignorable_404(path) |
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index f2f7f4d..e526da4 100644
a
|
b
|
from django.test.utils import override_settings
|
22 | 22 | from django.utils import six |
23 | 23 | from django.utils.encoding import force_str |
24 | 24 | from django.utils.six.moves import xrange |
25 | | from django.utils.unittest import expectedFailure |
| 25 | from django.utils.unittest import expectedFailure, skipIf |
26 | 26 | |
27 | 27 | from transactions.tests import IgnorePendingDeprecationWarningsMixin |
28 | 28 | |
… |
… |
class BrokenLinkEmailsMiddlewareTest(TestCase):
|
320 | 320 | BrokenLinkEmailsMiddleware().process_response(self.req, self.resp) |
321 | 321 | self.assertEqual(len(mail.outbox), 0) |
322 | 322 | |
| 323 | @skipIf(six.PY3, "HTTP_REFERER is str type on Python 3") |
| 324 | def test_404_error_nonascii_referrer(self): |
| 325 | # Such referer strings should not happen, but anyway, if it happens, |
| 326 | # let's not crash |
| 327 | self.req.META['HTTP_REFERER'] = b'http://testserver/c/\xd0\xbb\xd0\xb8/' |
| 328 | BrokenLinkEmailsMiddleware().process_response(self.req, self.resp) |
| 329 | self.assertEqual(len(mail.outbox), 1) |
| 330 | |
323 | 331 | |
324 | 332 | class ConditionalGetMiddlewareTest(TestCase): |
325 | 333 | urls = 'middleware.cond_get_urls' |