diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 0d84c8b4d..b9478c4de 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1111,13 +1111,14 @@ class LocalFileStorage(StorageInterface): def split_path(self, path): path = to_unicode(path) split = path.split("/") + if len(split) == 1: return "", split[0] - else: - return self.join_path(*split[:-1]), split[-1] + + return self.path_in_storage(self.join_path(*split[:-1])), split[-1] def join_path(self, *path): - return "/".join(map(to_unicode, path)) + return self.path_in_storage("/".join(map(to_unicode, path))) def sanitize(self, path): """ @@ -1233,7 +1234,7 @@ class LocalFileStorage(StorageInterface): if path.startswith(self.basefolder): path = path[len(self.basefolder) :] path = path.replace(os.path.sep, "/") - if path.startswith("/"): + while path.startswith("/"): path = path[1:] return path diff --git a/tests/filemanager/test_localstorage.py b/tests/filemanager/test_localstorage.py index c6394a092..dd4594f02 100644 --- a/tests/filemanager/test_localstorage.py +++ b/tests/filemanager/test_localstorage.py @@ -714,6 +714,31 @@ class LocalStorageTest(unittest.TestCase): self.assertEqual(0, len(gcode_metadata["links"])) self.assertEqual(1, len(stl_metadata["links"])) + @data( + ("", ("", "")), + ("/", ("", "")), + ("some_file.gco", ("", "some_file.gco")), + ("/some_file.gco", ("", "some_file.gco")), + ("some/folder/and/some file.gco", ("some/folder/and", "some file.gco")), + ("/some/folder/and/some file.gco", ("some/folder/and", "some file.gco")), + ) + @unpack + def test_split_path(self, input, expected): + actual = self.storage.split_path(input) + self.assertEqual(expected, actual) + + @data( + (("", ""), ""), + (("", "some_file.gco"), "some_file.gco"), + (("/", "some_file.gco"), "some_file.gco"), + (("some/folder/and", "some file.gco"), "some/folder/and/some file.gco"), + (("/some/folder/and", "some file.gco"), "some/folder/and/some file.gco"), + ) + @unpack + def test_join_path(self, input, expected): + actual = self.storage.join_path(*input) + self.assertEqual(expected, actual) + @data( ("some_file.gco", "some_file.gco", False), ("some file.gco", "some file.gco", False),