Ticket #15672: ticket-15672-force_unicode-with-ignore.diff

File ticket-15672-force_unicode-with-ignore.diff, 3.2 KB (added by kinpoo, 13 years ago)

ignore UnicodeDecodeError, does not handle it as bad request, let handle it as 404

  • django/core/handlers/modpython.py

    diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py
    index 7b25f0e..3ba5a3b 100755
    a b class ModPythonRequest(http.HttpRequest):  
    3333        # circumstances (it's out of mod_python's control a bit), so we use
    3434        # req.uri and some string manipulations to get the right value.
    3535        if root and req.uri.startswith(root):
    36             self.path_info = force_unicode(req.uri[len(root):])
     36            self.path_info = force_unicode(req.uri[len(root):], errors='ignore')
    3737        else:
    3838            self.path_info = self.path
    3939        if not self.path_info:
    class ModPythonHandler(BaseHandler):  
    176176        set_script_prefix(req.get_options().get('django.root', ''))
    177177        signals.request_started.send(sender=self.__class__)
    178178        try:
    179             try:
    180                 request = self.request_class(req)
    181             except UnicodeDecodeError:
    182                 logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path,
    183                     exc_info=sys.exc_info(),
    184                     extra={
    185                         'status_code': 400,
    186                         'request': request
    187                     }
    188                 )
    189                 response = http.HttpResponseBadRequest()
    190             else:
    191                 response = self.get_response(request)
     179            request = self.request_class(req)
     180            response = self.get_response(request)
    192181        finally:
    193182            signals.request_finished.send(sender=self.__class__)
    194183
  • django/core/handlers/wsgi.py

    diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
    index 537154c..24bf5dd 100755
    a b class LimitedStream(object):  
    117117class WSGIRequest(http.HttpRequest):
    118118    def __init__(self, environ):
    119119        script_name = base.get_script_name(environ)
    120         path_info = force_unicode(environ.get('PATH_INFO', u'/'))
     120        path_info = force_unicode(environ.get('PATH_INFO', u'/'), errors='ignore')
    121121        if not path_info or path_info == script_name:
    122122            # Sometimes PATH_INFO exists, but is empty (e.g. accessing
    123123            # the SCRIPT_NAME URL without a trailing slash). We really need to
    class WSGIHandler(base.BaseHandler):  
    258258        set_script_prefix(base.get_script_name(environ))
    259259        signals.request_started.send(sender=self.__class__)
    260260        try:
    261             try:
    262                 request = self.request_class(environ)
    263             except UnicodeDecodeError:
    264                 logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path,
    265                     exc_info=sys.exc_info(),
    266                     extra={
    267                         'status_code': 400,
    268                         'request': request
    269                     }
    270                 )
    271                 response = http.HttpResponseBadRequest()
    272             else:
    273                 response = self.get_response(request)
     261            request = self.request_class(environ)
     262            response = self.get_response(request)
    274263        finally:
    275264            signals.request_finished.send(sender=self.__class__)
    276265
Back to Top