summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-06-03 14:31:55 (GMT)
committerGeorg Brandl <georg@python.org>2005-06-03 14:31:55 (GMT)
commitbab518b5afe7aacc21466e575e54b1f6254aa4f8 (patch)
tree380946598b2a09809cfc10559e4ed3c39950d10c /Lib
parentd855c5888e3e3e2c22b8773c5743d5a689274eac (diff)
downloadcpython-bab518b5afe7aacc21466e575e54b1f6254aa4f8.zip
cpython-bab518b5afe7aacc21466e575e54b1f6254aa4f8.tar.gz
cpython-bab518b5afe7aacc21466e575e54b1f6254aa4f8.tar.bz2
Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
component of the path.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/posixpath.py2
-rw-r--r--Lib/test/test_posixpath.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index b29eedc..261e5a7 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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])
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 0a6ed99..b2d8d40 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -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):