diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-08-27 00:47:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 00:47:10 (GMT) |
commit | 7475aa2c590e33a47f5e79e4079bca0645e93f2f (patch) | |
tree | dce7c1e5c16d1e2e2eb860d5b00db171aaca0ce2 /Lib | |
parent | 57b698886b47bb81c782c2ba80a8a72fe66c7aad (diff) | |
download | cpython-7475aa2c590e33a47f5e79e4079bca0645e93f2f.zip cpython-7475aa2c590e33a47f5e79e4079bca0645e93f2f.tar.gz cpython-7475aa2c590e33a47f5e79e4079bca0645e93f2f.tar.bz2 |
bpo-33660: Fix PosixPath to resolve a relative path on root (GH-21975)
(cherry picked from commit 94ad6c674f7687ef22853cb8d42b440d6b42ddc8)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pathlib.py | 5 | ||||
-rw-r--r-- | Lib/test/test_pathlib.py | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index ff8bac9..4f72bab 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -329,7 +329,10 @@ class _PosixFlavour(_Flavour): # parent dir path, _, _ = path.rpartition(sep) continue - newpath = path + sep + name + if path.endswith(sep): + newpath = path + name + else: + newpath = path + sep + name if newpath in seen: # Already seen this path path = seen[newpath] diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 3622694..e9f928a 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2214,6 +2214,15 @@ class PosixPathTest(_BasePathTest, unittest.TestCase): st = os.stat(join('other_new_file')) self.assertEqual(stat.S_IMODE(st.st_mode), 0o644) + def test_resolve_root(self): + current_directory = os.getcwd() + try: + os.chdir('/') + p = self.cls('spam') + self.assertEqual(str(p.resolve()), '/spam') + finally: + os.chdir(current_directory) + def test_touch_mode(self): old_mask = os.umask(0) self.addCleanup(os.umask, old_mask) |