]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 18 Feb 2013 10:20:44 +0000 (12:20 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 18 Feb 2013 10:20:44 +0000 (12:20 +0200)
Lib/posixpath.py
Lib/test/test_posixpath.py

index 5b2513ad16f6a1c5413f8841b50ebfb4610105ce..d65dc757b298e255e96969cd30b89b469de48b8c 100644 (file)
@@ -382,9 +382,11 @@ def _joinrealpath(path, rest, seen):
         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):
index 23def061368d0102ec8c1e040add0029a15f2f86..7443e3001bd65026201ba5af1a5517b1bdf34796 100644 (file)
@@ -214,6 +214,16 @@ class PosixPathTest(unittest.TestCase):
         self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz")
         self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar")
 
+    def test_realpath_curdir(self):
+        self.assertEqual(realpath('.'), os.getcwd())
+        self.assertEqual(realpath('./.'), os.getcwd())
+        self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
+
+    def test_realpath_pardir(self):
+        self.assertEqual(realpath('..'), dirname(os.getcwd()))
+        self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
+        self.assertEqual(realpath('/'.join(['..'] * 100)), '/')
+
     if hasattr(os, "symlink"):
         def test_realpath_basic(self):
             # Basic operation.