mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-45506: Normalize _PyPathConfig.stdlib_dir when calculated. (#29040)
The recently added PyConfig.stdlib_dir was being set with ".." entries. When __file__ was added for from modules this caused a problem on out-of-tree builds. This PR fixes that by normalizing "stdlib_dir" when it is calculated in getpath.c. https://bugs.python.org/issue45506
This commit is contained in:
parent
f30ad65dbf
commit
17c61045c5
6 changed files with 236 additions and 24 deletions
|
@ -304,25 +304,51 @@ class PosixPathTest(unittest.TestCase):
|
|||
for path in ('~', '~/.local', '~vstinner/'):
|
||||
self.assertEqual(posixpath.expanduser(path), path)
|
||||
|
||||
def test_normpath(self):
|
||||
self.assertEqual(posixpath.normpath(""), ".")
|
||||
self.assertEqual(posixpath.normpath("/"), "/")
|
||||
self.assertEqual(posixpath.normpath("//"), "//")
|
||||
self.assertEqual(posixpath.normpath("///"), "/")
|
||||
self.assertEqual(posixpath.normpath("///foo/.//bar//"), "/foo/bar")
|
||||
self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"),
|
||||
"/foo/baz")
|
||||
self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar")
|
||||
NORMPATH_CASES = [
|
||||
("", "."),
|
||||
("/", "/"),
|
||||
("/.", "/"),
|
||||
("/./", "/"),
|
||||
("/.//.", "/"),
|
||||
("/foo", "/foo"),
|
||||
("/foo/bar", "/foo/bar"),
|
||||
("//", "//"),
|
||||
("///", "/"),
|
||||
("///foo/.//bar//", "/foo/bar"),
|
||||
("///foo/.//bar//.//..//.//baz///", "/foo/baz"),
|
||||
("///..//./foo/.//bar", "/foo/bar"),
|
||||
(".", "."),
|
||||
(".//.", "."),
|
||||
("..", ".."),
|
||||
("../", ".."),
|
||||
("../foo", "../foo"),
|
||||
("../../foo", "../../foo"),
|
||||
("../foo/../bar", "../bar"),
|
||||
("../../foo/../bar/./baz/boom/..", "../../bar/baz"),
|
||||
("/..", "/"),
|
||||
("/..", "/"),
|
||||
("/../", "/"),
|
||||
("/..//", "/"),
|
||||
("//..", "//"),
|
||||
("/../foo", "/foo"),
|
||||
("/../../foo", "/foo"),
|
||||
("/../foo/../", "/"),
|
||||
("/../foo/../bar", "/bar"),
|
||||
("/../../foo/../bar/./baz/boom/..", "/bar/baz"),
|
||||
("/../../foo/../bar/./baz/boom/.", "/bar/baz/boom"),
|
||||
]
|
||||
|
||||
self.assertEqual(posixpath.normpath(b""), b".")
|
||||
self.assertEqual(posixpath.normpath(b"/"), b"/")
|
||||
self.assertEqual(posixpath.normpath(b"//"), b"//")
|
||||
self.assertEqual(posixpath.normpath(b"///"), b"/")
|
||||
self.assertEqual(posixpath.normpath(b"///foo/.//bar//"), b"/foo/bar")
|
||||
self.assertEqual(posixpath.normpath(b"///foo/.//bar//.//..//.//baz"),
|
||||
b"/foo/baz")
|
||||
self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"),
|
||||
b"/foo/bar")
|
||||
def test_normpath(self):
|
||||
for path, expected in self.NORMPATH_CASES:
|
||||
with self.subTest(path):
|
||||
result = posixpath.normpath(path)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
path = path.encode('utf-8')
|
||||
expected = expected.encode('utf-8')
|
||||
with self.subTest(path, type=bytes):
|
||||
result = posixpath.normpath(path)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
@skip_if_ABSTFN_contains_backslash
|
||||
def test_realpath_curdir(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue