Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion fs/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def combine(path1, path2):

"""
if not path1:
return path2.lstrip()
return path2
return "{}/{}".format(path1.rstrip("/"), path2.lstrip("/"))


Expand Down
6 changes: 6 additions & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def test_combine(self):
self.assertEqual(combine("", "bar"), "bar")
self.assertEqual(combine("foo", "bar"), "foo/bar")

def test_combine_preserves_leading_whitespace(self):
for path in (" report.txt", "\tfile", " directory/file"):
self.assertEqual(combine("", path), path)
self.assertEqual(combine("foo", path), "foo/" + path)
self.assertEqual(combine("", "/file"), "/file")

def test_parts(self):
self.assertEqual(parts("/"), ["/"])
self.assertEqual(parts(""), ["./"])
Expand Down
7 changes: 7 additions & 0 deletions tests/test_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def test_on_error_invalid(self):
with self.assertRaises(TypeError):
walk.Walker(on_error="nope")

def test_files_preserve_leading_whitespace_at_relative_root(self):
with MemoryFS() as fs:
fs.writetext(" report.txt", "content")
paths = list(self.walker.files(fs, path=""))
self.assertEqual(paths, [" report.txt"])
self.assertEqual(fs.readtext(paths[0]), "content")


class TestBoundWalkerBase(unittest.TestCase):
def setUp(self):
Expand Down