(original) (raw)

changeset: 82247:50ed06b3d419 branch: 2.7 parent: 82243:a80ea934da9a user: Serhiy Storchaka storchaka@gmail.com date: Mon Feb 18 12:20:44 2013 +0200 files: Lib/posixpath.py Lib/test/test_posixpath.py description: Fix posixpath.realpath() for multiple pardirs (fixes issue #6975). diff -r a80ea934da9a -r 50ed06b3d419 Lib/posixpath.py --- a/Lib/posixpath.py Mon Feb 18 11:14:04 2013 +0200 +++ b/Lib/posixpath.py Mon Feb 18 12:20:44 2013 +0200 @@ -382,9 +382,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 -r a80ea934da9a -r 50ed06b3d419 Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py Mon Feb 18 11:14:04 2013 +0200 +++ b/Lib/test/test_posixpath.py Mon Feb 18 12:20:44 2013 +0200 @@ -214,6 +214,16 @@ 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. /storchaka@gmail.com