changeset: 35006:65c95ad672ae branch: legacy-trunk parent: 35004:8880d91cdb09 user: Georg Brandl date: Fri Jun 03 14:28:50 2005 +0000 files: Lib/posixpath.py Lib/test/test_posixpath.py Misc/NEWS description: Bug #1213894: os.path.realpath didn't resolve symlinks that were the first component of the path. diff -r 8880d91cdb09 -r 65c95ad672ae Lib/posixpath.py --- a/Lib/posixpath.py Fri Jun 03 14:12:21 2005 +0000 +++ b/Lib/posixpath.py Fri Jun 03 14:28:50 2005 +0000 @@ -414,7 +414,7 @@ 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 -r 8880d91cdb09 -r 65c95ad672ae Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py Fri Jun 03 14:12:21 2005 +0000 +++ b/Lib/test/test_posixpath.py Fri Jun 03 14:28:50 2005 +0000 @@ -476,6 +476,26 @@ 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): diff -r 8880d91cdb09 -r 65c95ad672ae Misc/NEWS --- a/Misc/NEWS Fri Jun 03 14:12:21 2005 +0000 +++ b/Misc/NEWS Fri Jun 03 14:28:50 2005 +0000 @@ -136,6 +136,9 @@ 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