[Python-checkins] cpython (merge 3.2 -> 3.3): Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).
serhiy.storchaka
python-checkins at python.org
Mon Feb 18 11:24:42 CET 2013
http://hg.python.org/cpython/rev/aad7e68eff0a
changeset: 82249:aad7e68eff0a
branch: 3.3
parent: 82245:88c04657c9f1
parent: 82248:cb3fbadb65aa
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Feb 18 12:21:30 2013 +0200
summary:
Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).
files:
Lib/posixpath.py | 6 ++++--
Lib/test/test_posixpath.py | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -418,9 +418,11 @@
if name == pardir:
# parent dir
if path:
- path = dirname(path)
+ path, name = split(path)
+ if name == pardir:
+ path = join(path, pardir, pardir)
else:
- path = name
+ path = pardir
continue
newpath = join(path, name)
if not islink(newpath):
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -340,6 +340,24 @@
self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"),
b"/foo/bar")
+ def test_realpath_curdir(self):
+ self.assertEqual(realpath('.'), os.getcwd())
+ self.assertEqual(realpath('./.'), os.getcwd())
+ self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
+
+ self.assertEqual(realpath(b'.'), os.getcwdb())
+ self.assertEqual(realpath(b'./.'), os.getcwdb())
+ self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb())
+
+ def test_realpath_pardir(self):
+ self.assertEqual(realpath('..'), dirname(os.getcwd()))
+ self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
+ self.assertEqual(realpath('/'.join(['..'] * 100)), '/')
+
+ self.assertEqual(realpath(b'..'), dirname(os.getcwdb()))
+ self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb())))
+ self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/')
+
@unittest.skipUnless(hasattr(os, "symlink"),
"Missing symlink implementation")
@skip_if_ABSTFN_contains_backslash
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list