From be3f851411f54b71251743997c1e8b2485f99de2 Mon Sep 17 00:00:00 2001
From: Senthil Kumaran <senthil@uthcode.com>
Date: Fri, 16 Mar 2012 01:13:50 -0700
Subject: [PATCH] closes issue10484 - Fix the http.server's cgi PATH_INFO
 handling problem

---
 Lib/http/server.py           | 9 ++++++++-
 Lib/test/test_httpservers.py | 1 +
 Misc/NEWS                    | 2 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/Lib/http/server.py b/Lib/http/server.py
index 6642729af5..537df90bf2 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -850,7 +850,14 @@ def _url_collapse_path_split(path):
     # Filter out blank non trailing parts before consuming the '..'.
     path_parts = [part for part in path_parts[:-1] if part] + path_parts[-1:]
     if path_parts:
-        tail_part = path_parts.pop()
+        # Special case for CGI's for PATH_INFO
+        if path.startswith('/cgi-bin') or path.startswith('/htbin'):
+            tail_part = []
+            while path_parts[-1] not in ('cgi-bin','htbin'):
+                tail_part.insert(0,path_parts.pop())
+            tail_part = "/".join(tail_part)
+        else:
+            tail_part = path_parts.pop()
     else:
         tail_part = ''
     head_parts = []
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index e83c048ed9..4d58e4bac3 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -377,6 +377,7 @@ class CGIHTTPServerTestCase(BaseTestCase):
             '/.//': ('/', ''),
             'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
             '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
+            '/cgi-bin/file1.py/PATH-INFO': ('/cgi-bin', 'file1.py/PATH-INFO'),
             'a': ('/', 'a'),
             '/a': ('/', 'a'),
             '//a': ('/', 'a'),
diff --git a/Misc/NEWS b/Misc/NEWS
index 65b22e6f19..772f78e97d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #10484: Fix the CGIHTTPServer's PATH_INFO handling problem.
+
 - Issue #11199: Fix the with urllib which hangs on particular ftp urls.
 
 - Issue #14062: Header objects now correctly respect the 'linesep' setting
-- 
2.40.0