Skip to content

Commit

Permalink
bpo-33660: Fix PosixPath to resolve a relative path on root
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 authored and ambv committed Aug 27, 2020
1 parent 82e7948 commit 94ad6c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ def _resolve(path, rest):
# 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]
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,15 @@ def test_open_mode(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix pathlib.PosixPath to resolve a relative path located on the root
directory properly.

0 comments on commit 94ad6c6

Please sign in to comment.