🐛 Normalize paths returned by split_path/join_path

See #4719
This commit is contained in:
Gina Häußge committed 2023-12-06 17:36:55 +01:00
1 parent 7557482948
commit 5229564196
2 files changed
+30 -4

No files matched your search

+5 -4
View File
@@ -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
+25
View File
@@ -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),