Skip to content

Commit

Permalink
Ignore empty segments.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 4, 2023
1 parent 2085494 commit 0f4122a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ def with_segments(self, *pathsegments):

@classmethod
def _parse_path(cls, path):
if not path:
return '', '', []
sep = cls.pathmod.sep
altsep = cls.pathmod.altsep
if altsep:
Expand Down Expand Up @@ -605,12 +603,13 @@ def __init__(self, *args):
"argument should be a str or an os.PathLike "
"object where __fspath__ returns a str, "
f"not {type(path).__name__!r}")
paths.append(path)
if path:
paths.append(path)
self._raw_paths = paths
if len(paths) == 1:
self._raw_path_cached = paths[0]
elif len(paths) == 0:
self._raw_path_cached = ''
self._raw_path_cached = '.'
self._resolving = False

def __reduce__(self):
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ def test_fspath_common(self):
p = P('a/b')
self._check_str(p.__fspath__(), ('a/b',))
self._check_str(os.fspath(p), ('a/b',))
self.assertEqual('.', P().__fspath__())
self.assertEqual('.', P('').__fspath__())
self.assertEqual('.', P('.').__fspath__())
self.assertEqual('.', P('', '').__fspath__())
self.assertEqual('.', P('.', '').__fspath__())
self.assertEqual('.', P('', '.').__fspath__())
self.assertEqual(f'.{self.sep}.', P('.', '.').__fspath__())

def test_bytes(self):
P = self.cls
Expand Down

0 comments on commit 0f4122a

Please sign in to comment.