[Zope-dev] bug in CatalogAwareness?
Steve Alexander
steve@cat-box.net
Wed, 23 Aug 2000 20:58:30 +0100
I just checked out the latest Zope 2 CVS.
In lib/python/Products/ZCatalog/CatalogAwareness.py, the method "url":
def url(self, ftype=urllib.splittype, fhost=urllib.splithost):
"""Return a SCRIPT_NAME-based url for an object."""
if hasattr(self, 'DestinationURL') and \
callable(self.DestinationURL):
url='%s/%s' % (self.DestinationURL(), self.id)
else: url=self.absolute_url()
type, uri=ftype(url)
host, uri=fhost(uri)
script_name=self.REQUEST['SCRIPT_NAME']
__traceback_info__=(`uri`, `script_name`)
if script_name:
uri=filter(None, string.split(uri, script_name))[0]
* if uri[0] != '/': uri = '/' + uri
* uri=uri or '/'
return urllib.unquote(uri)
I'm suspicious of the two lines marked with a "*".
The line
uri=uri or '/'
seems to imply that url can be the empty string, or possibly None.
However, the line before
if uri[0] != '/': uri = '/' + uri
Will fail with an IndexError if uri is ''.
Perhaps the two lines ought to be replaced with:
uri=uri and uri[0]!='/' and '/'+uri or uri or '/'
and perhaps a comment
# input output
# None '/'
# '' '/'
# '/' '/'
# 'foo' '/foo'
# '/foo' '/foo'
This is now in the Collector:
http://classic.zope.org:8080/Collector/1551/view
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net