diff options
| author | Sergey Shepelev <temotor@gmail.com> | 2018-03-07 10:48:07 +0300 |
|---|---|---|
| committer | Sergey Shepelev <temotor@gmail.com> | 2018-03-11 01:04:18 +0300 |
| commit | 4e576cbca07cd2c50da4baffd033a67c2ab10d1a (patch) | |
| tree | fbad231c2f01d3ce73dd538df5db7df4b38ba6d8 /eventlet/wsgi.py | |
| parent | 6c6cfc565f743c9de88fd131ec392cfb2162a984 (diff) | |
| download | eventlet-4e576cbca07cd2c50da4baffd033a67c2ab10d1a.tar.gz | |
wsgi: latin-1 encoding dance for environ[PATH_INFO]
https://www.python.org/dev/peps/pep-0333/#unicode-issues
https://github.com/eventlet/eventlet/issues/468
Diffstat (limited to 'eventlet/wsgi.py')
| -rw-r--r-- | eventlet/wsgi.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index 7576f0e..9f49090 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -59,6 +59,12 @@ def addr_to_host_port(addr): return (host, port) +def encode_dance(s): + if not isinstance(s, bytes): + s = s.encode('utf-8', 'replace') + return s.decode('latin1') + + # Collections of error codes to compare against. Not all attributes are set # on errno module on all platforms, so some are literals :( BAD_SOCK = set((errno.EBADF, 10053)) @@ -631,7 +637,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): pq = self.path.split('?', 1) env['RAW_PATH_INFO'] = pq[0] - env['PATH_INFO'] = urllib.parse.unquote(pq[0]) + env['PATH_INFO'] = encode_dance(urllib.parse.unquote(pq[0])) if len(pq) > 1: env['QUERY_STRING'] = pq[1] |
