mirror of https://github.com/python/cpython.git
Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).
This commit is contained in:
parent
fbc737eda1
commit
142d2bc3f1
|
@ -382,9 +382,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):
|
||||
|
|
|
@ -214,6 +214,16 @@ def test_normpath(self):
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue