[issue14565] is_cgi doesn't function as documented for cgi_directories
Glenn Linderman
report at bugs.python.org
Thu Apr 12 20:21:06 CEST 2012
New submission from Glenn Linderman <v+python at g.nevcal.com>:
I notice a deficiency in is_cgi: there is no documentation requiring cgi_directories to be a single part, only that the initial value happens to be a list of two directories, each of which have only a single part or level. The description of is_cgi, however, only requires that the strings in self.cgi_directories be prefixes of self.path, followed by "/" or end of string. While it is not at all clear that being followed by end of string would produce useful results, the description does allow for multiple parts in the directory, but the implementation does not.
Consider a potential value in an overridden or augmented cgi_directories such as '/subdomain/cgi-bin'. The current is_cgi wouldn't handle that.
Solution: replace the following is_cgi code (from current trunk):
collapsed_path = _url_collapse_path(self.path)
dir_sep = collapsed_path.find('/', 1)
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
if head in self.cgi_directories:
self.cgi_info = head, tail
return True
return False
with:
cln = len( collapsed_path )
found = False
for ix in self.cgi_directories:
ln = len( ix )
print('is_cgi: %d %d - %s - %s'
% ( ln, cln, ix, collapsed_path ))
if ln == cln and ix == collapsed_path:
self.cgi_info = ( ix, '')
found = True
break
elif ( ln < cln and collapsed_path[ ln ] == '/'
and collapsed_path.startswith( ix )):
self.cgi_info = ( ix, collapsed_path[ ln+1: ])
found = True
break
return found
----------
messages: 158158
nosy: v+python
priority: normal
severity: normal
status: open
title: is_cgi doesn't function as documented for cgi_directories
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14565>
_______________________________________
More information about the Python-bugs-list
mailing list