Code

Ticket #16541: ticket-16541.diff

File ticket-16541.diff, 3.0 KB (added by kinpoo, 3 years ago)
Line 
1diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py
2index eba9dd3..6be33a0 100644
3--- a/django/core/handlers/modpython.py
4+++ b/django/core/handlers/modpython.py
5@@ -32,7 +32,7 @@ class ModPythonRequest(http.HttpRequest):
6         # circumstances (it's out of mod_python's control a bit), so we use
7         # req.uri and some string manipulations to get the right value.
8         if root and req.uri.startswith(root):
9-            self.path_info = force_unicode(req.uri[len(root):])
10+            self.path_info = force_unicode(req.uri[len(root):], errors='ignore')
11         else:
12             self.path_info = self.path
13         if not self.path_info:
14@@ -149,18 +149,8 @@ class ModPythonHandler(BaseHandler):
15         set_script_prefix(req.get_options().get('django.root', ''))
16         signals.request_started.send(sender=self.__class__)
17         try:
18-            try:
19-                request = self.request_class(req)
20-            except UnicodeDecodeError:
21-                logger.warning('Bad Request (UnicodeDecodeError)',
22-                    exc_info=sys.exc_info(),
23-                    extra={
24-                        'status_code': 400,
25-                    }
26-                )
27-                response = http.HttpResponseBadRequest()
28-            else:
29-                response = self.get_response(request)
30+            request = self.request_class(req)
31+            response = self.get_response(request)
32         finally:
33             signals.request_finished.send(sender=self.__class__)
34 
35diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
36index 56d2ba6..c121ce3 100644
37--- a/django/core/handlers/wsgi.py
38+++ b/django/core/handlers/wsgi.py
39@@ -115,7 +115,7 @@ class LimitedStream(object):
40 class WSGIRequest(http.HttpRequest):
41     def __init__(self, environ):
42         script_name = base.get_script_name(environ)
43-        path_info = force_unicode(environ.get('PATH_INFO', u'/'))
44+        path_info = force_unicode(environ.get('PATH_INFO', u'/'), errors='ignore')
45         if not path_info or path_info == script_name:
46             # Sometimes PATH_INFO exists, but is empty (e.g. accessing
47             # the SCRIPT_NAME URL without a trailing slash). We really need to
48@@ -216,18 +216,8 @@ class WSGIHandler(base.BaseHandler):
49         set_script_prefix(base.get_script_name(environ))
50         signals.request_started.send(sender=self.__class__)
51         try:
52-            try:
53-                request = self.request_class(environ)
54-            except UnicodeDecodeError:
55-                logger.warning('Bad Request (UnicodeDecodeError)',
56-                    exc_info=sys.exc_info(),
57-                    extra={
58-                        'status_code': 400,
59-                    }
60-                )
61-                response = http.HttpResponseBadRequest()
62-            else:
63-                response = self.get_response(request)
64+            request = self.request_class(environ)
65+            response = self.get_response(request)
66         finally:
67             signals.request_finished.send(sender=self.__class__)
68