]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-direct...
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 22 Dec 2006 13:25:02 +0000 (13:25 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 22 Dec 2006 13:25:02 +0000 (13:25 +0000)
Lib/CGIHTTPServer.py

index 7a5c8190d82c689d8dd52293ad345be07de402ad..c119c9a6930d23af7310cc3af38eda4382aa2889 100644 (file)
@@ -105,17 +105,36 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
 
     def run_cgi(self):
         """Execute a CGI script."""
+        path = self.path
         dir, rest = self.cgi_info
+        
+        i = path.find('/', len(dir) + 1)
+        while i >= 0:
+            nextdir = path[:i]
+            nextrest = path[i+1:]
+
+            scriptdir = self.translate_path(nextdir)
+            if os.path.isdir(scriptdir):
+                dir, rest = nextdir, nextrest
+                i = path.find('/', len(dir) + 1)
+            else:
+                break
+
+        # find an explicit query string, if present.
         i = rest.rfind('?')
         if i >= 0:
             rest, query = rest[:i], rest[i+1:]
         else:
             query = ''
+
+        # dissect the part after the directory name into a script name &
+        # a possible additional path, to be stored in PATH_INFO.
         i = rest.find('/')
         if i >= 0:
             script, rest = rest[:i], rest[i:]
         else:
             script, rest = rest, ''
+
         scriptname = dir + '/' + script
         scriptfile = self.translate_path(scriptname)
         if not os.path.exists(scriptfile):