Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 209d70e

Browse files
committed
closes issue10484 - Fix the http.server's cgi PATH_INFO handling problem
2 parents 2a1e74a + be3f851 commit 209d70e

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/http/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,14 @@ def _url_collapse_path_split(path):
865865
# Filter out blank non trailing parts before consuming the '..'.
866866
path_parts = [part for part in path_parts[:-1] if part] + path_parts[-1:]
867867
if path_parts:
868-
tail_part = path_parts.pop()
868+
# Special case for CGI's for PATH_INFO
869+
if path.startswith('/cgi-bin') or path.startswith('/htbin'):
870+
tail_part = []
871+
while path_parts[-1] not in ('cgi-bin','htbin'):
872+
tail_part.insert(0,path_parts.pop())
873+
tail_part = "/".join(tail_part)
874+
else:
875+
tail_part = path_parts.pop()
869876
else:
870877
tail_part = ''
871878
head_parts = []

Lib/test/test_httpservers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def test_url_collapse_path_split(self):
377377
'/.//': ('/', ''),
378378
'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
379379
'/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
380+
'/cgi-bin/file1.py/PATH-INFO': ('/cgi-bin', 'file1.py/PATH-INFO'),
380381
'a': ('/', 'a'),
381382
'/a': ('/', 'a'),
382383
'//a': ('/', 'a'),

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #10484: Fix the CGIHTTPServer's PATH_INFO handling problem.
28+
2729
- Issue #11199: Fix the with urllib which hangs on particular ftp urls.
2830

2931
- Issue #14222: Use the new time.steady() function instead of time.time() for

0 commit comments

Comments
 (0)