Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix iterdir() on path with trailing slash.
  • Loading branch information
barneygale committed Apr 17, 2023
commit b15b71eb593cfef54df6ee6170bf625b2ee9f251
3 changes: 2 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,11 @@ def __new__(cls, *args, **kwargs):
def _make_child_relpath(self, name):
path_str = str(self)
tail = self._tail
if tail:
if tail and tail[-1]:
path_str = f'{path_str}{self._flavour.sep}{name}'
elif path_str != '.':
path_str = f'{path_str}{name}'
tail = tail[:-1]
else:
path_str = name
path = type(self)(path_str)
Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,13 +1774,13 @@ def test_write_text_with_newlines(self):

def test_iterdir(self):
P = self.cls
p = P(BASE)
it = p.iterdir()
paths = set(it)
expected = ['dirA', 'dirB', 'dirC', 'dirE', 'fileA']
if os_helper.can_symlink():
expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop']
self.assertEqual(paths, { P(BASE, q) for q in expected })
for p in [P(BASE), P(BASE, '')]:
it = p.iterdir()
paths = set(it)
expected = ['dirA', 'dirB', 'dirC', 'dirE', 'fileA']
if os_helper.can_symlink():
expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop']
self.assertEqual(paths, { P(BASE, q) for q in expected })

@os_helper.skip_unless_symlink
def test_iterdir_symlink(self):
Expand Down