Message158015
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) |
|
Date |
User |
Action |
Args |
2012-04-11 09:30:14 | v+python | set | recipients:
+ v+python, fdrake, facundobatista, orsenthil, python-dev, Giovanni.Funchal |
2012-04-11 09:30:14 | v+python | set | messageid: <1334136614.17.0.242823625004.issue10484@psf.upfronthosting.co.za> |
2012-04-11 09:30:13 | v+python | link | issue10484 messages |
2012-04-11 09:30:13 | v+python | create | |
|