ca74dda
# HG changeset patch
ca74dda
# User Benjamin Peterson <benjamin@python.org>
ca74dda
# Date 1402796189 25200
ca74dda
# Node ID b4bab078876811c7d95231d08aa6fa7142fdda66
ca74dda
# Parent  bb8b0c7fefd0c5ed99b3f336178a4f9554a1d0ef
ca74dda
url unquote the path before checking if it refers to a CGI script (closes #21766)
ca74dda
ca74dda
diff --git a/Lib/CGIHTTPServer.py b/Lib/CGIHTTPServer.py
ca74dda
--- a/Lib/CGIHTTPServer.py
ca74dda
+++ b/Lib/CGIHTTPServer.py
ca74dda
@@ -84,7 +84,7 @@ class CGIHTTPRequestHandler(SimpleHTTPSe
ca74dda
         path begins with one of the strings in self.cgi_directories
ca74dda
         (and the next character is a '/' or the end of the string).
ca74dda
         """
ca74dda
-        collapsed_path = _url_collapse_path(self.path)
ca74dda
+        collapsed_path = _url_collapse_path(urllib.unquote(self.path))
ca74dda
         dir_sep = collapsed_path.find('/', 1)
ca74dda
         head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
ca74dda
         if head in self.cgi_directories:
ca74dda
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
ca74dda
--- a/Lib/test/test_httpservers.py
ca74dda
+++ b/Lib/test/test_httpservers.py
ca74dda
@@ -510,6 +510,11 @@ class CGIHTTPServerTestCase(BaseTestCase
ca74dda
                 (res.read(), res.getheader('Content-type'), res.status))
ca74dda
         self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
ca74dda
 
ca74dda
+    def test_urlquote_decoding_in_cgi_check(self):
ca74dda
+        res = self.request('/cgi-bin%2ffile1.py')
ca74dda
+        self.assertEqual((b'Hello World\n', 'text/html', 200),
ca74dda
+                (res.read(), res.getheader('Content-type'), res.status))
ca74dda
+
ca74dda
 
ca74dda
 class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
ca74dda
     """ Test url parsing """