summaryrefslogtreecommitdiff
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-08-30 22:05:26 +0000
committerTim Peters <tim.peters@gmail.com>2001-08-30 22:05:26 +0000
commit191e5297febe69b06efea0d9165a94b8b67757b4 (patch)
tree85d4b443fa75ab6eab126720fbc94c31ae657bbd /Lib/ntpath.py
parentae45738a90452f5e0bea0acfbb0b040ec05125ec (diff)
downloadcpython-191e5297febe69b06efea0d9165a94b8b67757b4.tar.gz
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.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 1be2961a4f..d55cc7c44f 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -407,7 +407,7 @@ def expandvars(path):
return res
-# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
+# 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!
@@ -421,15 +421,18 @@ def normpath(path):
comps = path.split("\\")
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] != '':
+ 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 = i + 1
+ i += 1
# If the path is now empty, substitute '.'
if not prefix and not comps:
comps.append('.')