Skip to content

Commit

Permalink
Fix join_filename return value when basename or extension are e…
Browse files Browse the repository at this point in the history
…mpty.
  • Loading branch information
fabiocaccamo committed Mar 19, 2024
1 parent f13bcfb commit c8c7301
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fsutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,10 @@ def join_filename(basename: str, extension: str) -> str:
"""
basename = basename.rstrip(".").strip()
extension = extension.replace(".", "").strip()
filename = f"{basename}.{extension}"
return filename
if basename and extension:
filename = f"{basename}.{extension}"
return filename
return basename or extension


def join_filepath(dirpath: PathIn, filename: str) -> str:
Expand Down
2 changes: 2 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ def test_join_filename(self):
self.assertEqual(fsutil.join_filename("Document", ".txt"), "Document.txt")
self.assertEqual(fsutil.join_filename(" Document ", " txt "), "Document.txt")
self.assertEqual(fsutil.join_filename("Document", " .txt "), "Document.txt")
self.assertEqual(fsutil.join_filename("Document", ""), "Document")
self.assertEqual(fsutil.join_filename("", "txt"), "txt")

def test_join_filepath(self):
self.assertEqual(
Expand Down

0 comments on commit c8c7301

Please sign in to comment.