]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8
authorMartin Panter <vadmium+py@gmail.com>
Sun, 17 Apr 2016 02:17:03 +0000 (02:17 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Sun, 17 Apr 2016 02:17:03 +0000 (02:17 +0000)
Patch by Anthony Sottile.

Lib/test/test_wsgiref.py
Lib/wsgiref/simple_server.py
Misc/ACKS
Misc/NEWS

index 3f800eff2d66d0e9731330ba76ae634b56cd712c..b7d02e868c9ffa3fdf1205567098924b35e2ca7d 100644 (file)
@@ -1,3 +1,4 @@
+from unittest import mock
 from unittest import TestCase
 from wsgiref.util import setup_testing_defaults
 from wsgiref.headers import Headers
@@ -221,6 +222,29 @@ class IntegrationTests(TestCase):
                 b"data",
                 out)
 
+    def test_cp1252_url(self):
+        def app(e, s):
+            s("200 OK", [
+                ("Content-Type", "text/plain"),
+                ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"),
+                ])
+            # PEP3333 says environ variables are decoded as latin1.
+            # Encode as latin1 to get original bytes
+            return [e["PATH_INFO"].encode("latin1")]
+
+        out, err = run_amock(
+            validator(app), data=b"GET /\x80%80 HTTP/1.0")
+        self.assertEqual(
+            [
+                b"HTTP/1.0 200 OK",
+                mock.ANY,
+                b"Content-Type: text/plain",
+                b"Date: Wed, 24 Dec 2008 13:29:32 GMT",
+                b"",
+                b"/\x80\x80",
+            ],
+            out.splitlines())
+
 
 class UtilityTests(TestCase):
 
index 378b316bbd457c977f50fb4a6cfff43f90191033..e396788cde1e3c094f6bc8617b358cc29dcf6d39 100644 (file)
@@ -82,7 +82,7 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
         else:
             path,query = self.path,''
 
-        env['PATH_INFO'] = urllib.parse.unquote_to_bytes(path).decode('iso-8859-1')
+        env['PATH_INFO'] = urllib.parse.unquote(path, 'iso-8859-1')
         env['QUERY_STRING'] = query
 
         host = self.address_string()
index 01b42f4f3e8ef4de6f2d9b31778da5cfbb32508f..e293ddc9c6d151875e3b06f652103fedf1a952a3 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1376,6 +1376,7 @@ Nir Soffer
 Paul Sokolovsky
 Evgeny Sologubov
 Cody Somerville
+Anthony Sottile
 Edoardo Spadolini
 Geoffrey Spear
 Clay Spence
index ec6626ffd01b25efbc7526fe862187687dbeb06a..94d8255eabd7fe25b53a0fcb693d410a2578034d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -107,6 +107,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8.  Patch by
+  Anthony Sottile.
+
 - Issue #26735: Fix :func:`os.urandom` on Solaris 11.3 and newer when reading
   more than 1,024 bytes: call ``getrandom()`` multiple times with a limit of
   1024 bytes per call.