[1.3.X] Fixed #15672 -- Refined changes made in r15918. Thanks, vung.

Backport from trunk (r16082).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16083 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-04-22 12:21:58 +00:00
parent 4d62386cad
commit e87c9da437
3 changed files with 10 additions and 3 deletions

View File

@ -179,11 +179,10 @@ class ModPythonHandler(BaseHandler):
try: try:
request = self.request_class(req) request = self.request_class(req)
except UnicodeDecodeError: except UnicodeDecodeError:
logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path, logger.warning('Bad Request (UnicodeDecodeError)',
exc_info=sys.exc_info(), exc_info=sys.exc_info(),
extra={ extra={
'status_code': 400, 'status_code': 400,
'request': request
} }
) )
response = http.HttpResponseBadRequest() response = http.HttpResponseBadRequest()

View File

@ -265,7 +265,6 @@ class WSGIHandler(base.BaseHandler):
exc_info=sys.exc_info(), exc_info=sys.exc_info(),
extra={ extra={
'status_code': 400, 'status_code': 400,
'request': request
} }
) )
response = http.HttpResponseBadRequest() response = http.HttpResponseBadRequest()

View File

@ -1,6 +1,8 @@
from django.utils import unittest from django.utils import unittest
from django.conf import settings from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from django.test import RequestFactory
class HandlerTests(unittest.TestCase): class HandlerTests(unittest.TestCase):
@ -23,3 +25,10 @@ class HandlerTests(unittest.TestCase):
# Reset settings # Reset settings
settings.MIDDLEWARE_CLASSES = old_middleware_classes settings.MIDDLEWARE_CLASSES = old_middleware_classes
def test_bad_path_info(self):
"""Tests for bug #15672 ('request' referenced before assignment)"""
environ = RequestFactory().get('/').environ
environ['PATH_INFO'] = '\xed'
handler = WSGIHandler()
response = handler(environ, lambda *a, **k: None)
self.assertEqual(response.status_code, 400)