fix(request) Workarount for nonlatin1 path info (PEP3333 compliance)
This commit is contained in:
committed by
Kurt Griffiths
parent
ee5278b362
commit
6b011038f6
@@ -220,6 +220,11 @@ class Request(object):
|
||||
# Normalize path
|
||||
path = env['PATH_INFO']
|
||||
if path:
|
||||
if six.PY3: # pragma: no cover
|
||||
# PEP 3333 specifies that PATH_INFO variable are always
|
||||
# "bytes tunneled as latin-1" and must be encoded back
|
||||
path = path.encode('latin1').decode('utf-8', 'replace')
|
||||
|
||||
if len(path) != 1 and path.endswith('/'):
|
||||
self.path = path[:-1]
|
||||
else:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import datetime
|
||||
import six
|
||||
import testtools
|
||||
|
||||
import ddt
|
||||
|
||||
@@ -107,6 +109,16 @@ class TestReqVars(testing.TestBase):
|
||||
|
||||
self.assertEqual(expected_uri, req.uri)
|
||||
|
||||
@testtools.skipUnless(six.PY3, 'Test only applies to Python 3')
|
||||
def test_nonlatin_path(self):
|
||||
cyrillic_path = u'/hello_\u043f\u0440\u0438\u0432\u0435\u0442'
|
||||
cyrillic_path_decoded = cyrillic_path.encode('utf-8').decode('latin1')
|
||||
req = Request(testing.create_environ(
|
||||
host='com',
|
||||
path=cyrillic_path_decoded,
|
||||
headers=self.headers))
|
||||
self.assertEqual(req.path, cyrillic_path)
|
||||
|
||||
def test_uri(self):
|
||||
uri = ('http://' + testing.DEFAULT_HOST + ':8080' +
|
||||
self.app + self.relative_uri)
|
||||
|
||||
Reference in New Issue
Block a user