]> granicus.if.org Git - python/commitdiff
Bug #1213894: os.path.realpath didn't resolve symlinks that were the first
authorGeorg Brandl <georg@python.org>
Fri, 3 Jun 2005 14:28:50 +0000 (14:28 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 3 Jun 2005 14:28:50 +0000 (14:28 +0000)
component of the path.

Lib/posixpath.py
Lib/test/test_posixpath.py
Misc/NEWS

index b29eedc38b56723e3c84358326eaf4b84fef0f07..261e5a7db26fe35c25793240f0c5587250d89c9f 100644 (file)
@@ -414,7 +414,7 @@ symbolic links encountered in the path."""
     if isabs(filename):
         bits = ['/'] + filename.split('/')[1:]
     else:
-        bits = filename.split('/')
+        bits = [''] + filename.split('/')
 
     for i in range(2, len(bits)+1):
         component = join(*bits[0:i])
index 0a6ed9903e596d1c5f82e944c5cac0d8d20b63b9..b2d8d406b78ce66731355bef6ce8391253867d22 100644 (file)
@@ -476,6 +476,26 @@ class PosixPathTest(unittest.TestCase):
                 self.safe_rmdir(ABSTFN + "/k/y")
                 self.safe_rmdir(ABSTFN + "/k")
                 self.safe_rmdir(ABSTFN)
+        
+        def test_realpath_resolve_first(self):
+            # Bug #1213894: The first component of the path, if not absolute,
+            # must be resolved too.
+
+            try:
+                old_path = abspath('.')
+                os.mkdir(ABSTFN)
+                os.mkdir(ABSTFN + "/k")
+                os.symlink(ABSTFN, ABSTFN + "link")
+                os.chdir(dirname(ABSTFN))
+                
+                base = basename(ABSTFN)
+                self.assertEqual(realpath(base + "link"), ABSTFN)
+                self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
+            finally:
+                os.chdir(old_path)
+                self.safe_remove(ABSTFN + "link")
+                self.safe_rmdir(ABSTFN + "/k")
+                self.safe_rmdir(ABSTFN)
 
         # Convenience functions for removing temporary files.
         def pass_os_error(self, func, filename):
index 196d7629ce7b07d887d2687e86a1729073628676..50f5a2718f722d1ee2a30a924288e9b6b4b1ad01 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -136,6 +136,9 @@ Extension Modules
 Library
 -------
 
+- Bug #1213894: os.path.realpath didn't resolve symlinks that were the first
+  component of the path.
+
 - Patch #1120353: The xmlrpclib module provides better, more transparent,
   support for datetime.{datetime,date,time} objects.  With use_datetime set
   to True, applications shouldn't have to fiddle with the DateTime wrapper