launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #22440
[Merge] lp:~twom/python-oops-wsgi/utf-8-encoding-parameters into lp:python-oops-wsgi
Tom Wardill has proposed merging lp:~twom/python-oops-wsgi/utf-8-encoding-parameters into lp:python-oops-wsgi.
Commit message:
UTF-8 encode parameters before attempting to quote
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~twom/python-oops-wsgi/utf-8-encoding-parameters/+merge/344961
UTF-8 passed to python2 urllib quote() will cause a KeyError, https://bugs.python.org/issue1712522
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~twom/python-oops-wsgi/utf-8-encoding-parameters into lp:python-oops-wsgi.
=== modified file 'oops_wsgi/middleware.py'
--- oops_wsgi/middleware.py 2014-07-24 17:53:23 +0000
+++ oops_wsgi/middleware.py 2018-05-02 13:59:43 +0000
@@ -300,9 +300,9 @@
url += quote(script_name)
if with_path_info:
if path_info is None:
- url += quote(environ.get('PATH_INFO',''))
+ url += quote(environ.get('PATH_INFO','').encode('UTF-8'))
else:
- url += quote(path_info)
+ url += quote(path_info.encode('UTF-8'))
if with_query_string:
if querystring is None:
if environ.get('QUERY_STRING'):
=== modified file 'oops_wsgi/tests/test_middleware.py'
--- oops_wsgi/tests/test_middleware.py 2013-05-22 15:59:31 +0000
+++ oops_wsgi/tests/test_middleware.py 2018-05-02 13:59:43 +0000
@@ -39,7 +39,7 @@
)
from oops_wsgi import make_app
-from oops_wsgi.middleware import generator_tracker
+from oops_wsgi.middleware import generator_tracker, construct_url
class MatchesOOPS:
@@ -641,3 +641,31 @@
for result in tracker:
pass
self.assertTrue(mock_app_body.close_called)
+
+
+class TestConstructURL(TestCase):
+
+ def test_with_normal_string(self):
+ result = construct_url(
+ {
+ 'HTTP_HOST': 'localhost:8000',
+ 'wsgi.url_scheme': 'http',
+ 'PATH_INFO': '/test/foo',
+ }
+ )
+ self.assertEqual(
+ result, 'http://localhost:8000/test/foo'
+ )
+
+ def test_with_unicode_string(self):
+ result = construct_url(
+ {
+ 'HTTP_HOST': 'localhost:8000',
+ 'wsgi.url_scheme': 'http',
+ 'PATH_INFO': u'/test/\xf9/',
+ }
+ )
+ self.assertEqual(
+ result,
+ 'http://localhost:8000/test/%C3%B9/'
+ )