summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Baker <phillbaker@retrodict.com>2020-08-28 11:56:09 -0400
committerGitHub <noreply@github.com>2020-08-28 11:56:09 -0400
commit017f5981783936dacb5455c481743ca8187efb0e (patch)
treef19d67f82302df766e290478766039225afad18c
parentbb646454916f64b0032a2e8c1adf17641a95bf95 (diff)
downloadroutes-017f5981783936dacb5455c481743ca8187efb0e.tar.gz
Add graceful fallback for invalid character encoding
For context see https://github.com/Pylons/webob/issues/161
-rw-r--r--routes/middleware.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/routes/middleware.py b/routes/middleware.py
index ba51ae3..4ee47da 100644
--- a/routes/middleware.py
+++ b/routes/middleware.py
@@ -61,9 +61,15 @@ class RoutesMiddleware(object):
if '_method' in qs:
req = Request(environ)
req.errors = 'ignore'
- if '_method' in req.GET:
+
+ try:
+ method = req.GET.get('_method')
+ except UnicodeDecodeError:
+ method = None
+
+ if method:
old_method = environ['REQUEST_METHOD']
- environ['REQUEST_METHOD'] = req.GET['_method'].upper()
+ environ['REQUEST_METHOD'] = method.upper()
if self.log_debug:
log.debug("_method found in QUERY_STRING, altering "
"request method to %s",
@@ -72,9 +78,15 @@ class RoutesMiddleware(object):
if req is None:
req = Request(environ)
req.errors = 'ignore'
- if '_method' in req.POST:
+
+ try:
+ method = req.POST.get('_method')
+ except UnicodeDecodeError:
+ method = None
+
+ if method:
old_method = environ['REQUEST_METHOD']
- environ['REQUEST_METHOD'] = req.POST['_method'].upper()
+ environ['REQUEST_METHOD'] = method.upper()
if self.log_debug:
log.debug("_method found in POST data, altering "
"request method to %s",