[issue10484] http.server.is_cgi fails to handle CGI URLs containing PATH_INFO

Glenn Linderman report at bugs.python.org
Wed Apr 11 11:30:14 CEST 2012


Glenn Linderman <v+python at g.nevcal.com> added the comment:

I note that there is no test for tail_part == '.'.  I suggest adding a couple, such as the following which I added to my local copy for testing of the next item:

            '/a/b/.': ('/a/b', ''),
            '/a/b/c/../d/e/../../../../f/../.': ('/', ''),

Given your comment that you found bugs in my code, I figured out how to run the tests against my code, and found the bugs. Here is a slightly shorter, more efficient (it cuts 40% off the execution time, see time_test.py), and to me much clearer version of _url_collapse_path_split, and it passes all the tests:

def _url_collapse_path_split(path):
    # Similar to os.path.split(os.path.normpath(path)) but specific to URL
    # path semantics rather than local operating system semantics.
    path_parts = path.split('/')
    head_parts = []
    for part in path_parts[:-1]:
        if part == '..':
            head_parts.pop() # IndexError if more '..' than prior parts
        elif part and part != '.':
            head_parts.append( part )
    if path_parts:
        tail_part = path_parts.pop()
        if tail_part:
            if tail_part == '..':
                head_parts.pop()
                tail_part = ''
            elif tail_part == '.':
                tail_part = ''
    else:
        tail_part = ''        
    return ('/' + '/'.join(head_parts), tail_part)

----------
Added file: http://bugs.python.org/file25175/time_test.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10484>
_______________________________________


More information about the Python-bugs-list mailing list