diff options
-rw-r--r-- | Lib/posixpath.py | 6 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 18 |
2 files changed, 22 insertions, 2 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 6390a865..e1d59b6 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -390,9 +390,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): diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 0d85727..ed56c51 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -283,6 +283,24 @@ class PosixPathTest(unittest.TestCase): self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"), b"/foo/bar") + def test_realpath_curdir(self): + self.assertEqual(realpath('.'), os.getcwd()) + self.assertEqual(realpath('./.'), os.getcwd()) + self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd()) + + self.assertEqual(realpath(b'.'), os.getcwdb()) + self.assertEqual(realpath(b'./.'), os.getcwdb()) + self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb()) + + def test_realpath_pardir(self): + self.assertEqual(realpath('..'), dirname(os.getcwd())) + self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd()))) + self.assertEqual(realpath('/'.join(['..'] * 100)), '/') + + self.assertEqual(realpath(b'..'), dirname(os.getcwdb())) + self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb()))) + self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/') + @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") @skip_if_ABSTFN_contains_backslash |