[Python-checkins] CVS: python/dist/src/Lib ntpath.py,1.40,1.41
Tim Peters
tim_one@users.sourceforge.net
Thu, 30 Aug 2001 15:05:28 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv29850/python/Lib
Modified Files:
ntpath.py
Log Message:
SF bug #456621: normpath on Win32 not collapsing c:\\..
I actually rewrote normpath quite a bit: it had no test cases, and as
soon as I starting writing some I found several cases that didn't make
sense.
Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** ntpath.py 2001/07/27 08:09:54 1.40
--- ntpath.py 2001/08/30 22:05:26 1.41
***************
*** 408,412 ****
! # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
# Previously, this function also truncated pathnames to 8+3 format,
# but as this module is called "ntpath", that's obviously wrong!
--- 408,412 ----
! # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
# Previously, this function also truncated pathnames to 8+3 format,
# but as this module is called "ntpath", that's obviously wrong!
***************
*** 422,434 ****
i = 0
while i < len(comps):
! if comps[i] == '.':
! del comps[i]
! elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
! del comps[i-1:i+1]
! i = i - 1
! elif comps[i] == '' and i > 0 and comps[i-1] != '':
del comps[i]
else:
! i = i + 1
# If the path is now empty, substitute '.'
if not prefix and not comps:
--- 422,437 ----
i = 0
while i < len(comps):
! if comps[i] in ('.', ''):
del comps[i]
+ elif comps[i] == '..':
+ if i > 0 and comps[i-1] != '..':
+ del comps[i-1:i+1]
+ i -= 1
+ elif i == 0 and prefix.endswith("\\"):
+ del comps[i]
+ else:
+ i += 1
else:
! i += 1
# If the path is now empty, substitute '.'
if not prefix and not comps: