mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).
This commit is contained in:
commit
2a47954895
2 changed files with 22 additions and 2 deletions
|
@ -390,9 +390,11 @@ def _joinrealpath(path, rest, seen):
|
||||||
if name == pardir:
|
if name == pardir:
|
||||||
# parent dir
|
# parent dir
|
||||||
if path:
|
if path:
|
||||||
path = dirname(path)
|
path, name = split(path)
|
||||||
|
if name == pardir:
|
||||||
|
path = join(path, pardir, pardir)
|
||||||
else:
|
else:
|
||||||
path = name
|
path = pardir
|
||||||
continue
|
continue
|
||||||
newpath = join(path, name)
|
newpath = join(path, name)
|
||||||
if not islink(newpath):
|
if not islink(newpath):
|
||||||
|
|
|
@ -283,6 +283,24 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"),
|
self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"),
|
||||||
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"),
|
@unittest.skipUnless(hasattr(os, "symlink"),
|
||||||
"Missing symlink implementation")
|
"Missing symlink implementation")
|
||||||
@skip_if_ABSTFN_contains_backslash
|
@skip_if_ABSTFN_contains_backslash
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue