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
7 changes: 6 additions & 1 deletion lean/components/util/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ def _format_local_path(self, cloud_path: str) -> str:
new_components = []

for component in cloud_path.split("/"):
# Leading, trailing and repeated separators don't name a directory
if not component:
continue

# Some names are reserved
for reserved_name in reserved_names:
# If the component is a reserved name, we add an underscore to it so it can be used
Expand All @@ -471,7 +475,8 @@ def _format_local_path(self, cloud_path: str) -> str:
# Components cannot end with a period
component = component.rstrip(".")

new_components.append(component)
# An empty component would be dropped from the path or make it absolute, outside the workspace
new_components.append(component or "_")

cloud_path = "/".join(new_components)

Expand Down
15 changes: 15 additions & 0 deletions tests/components/util/test_project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,18 @@ def test_get_cloud_projects_libraries_filters_libraries_that_cannot_be_accessed(

assert _lists_are_equal(libraries, own_project_libraries)
assert _lists_are_equal(libraries_not_found, collab_libraries)


@pytest.mark.parametrize("cloud_name,expected_name", [(":/Strategy", "_/Strategy"),
("Folder/ /Strategy", "Folder/_/Strategy"),
("../Strategy", "_/Strategy"),
("::", "_"),
("/Strategy", "Strategy"),
("Folder/Strategy/", "Folder/Strategy")])
def test_get_local_project_path_stays_inside_workspace_when_a_component_sanitizes_to_nothing(cloud_name: str,
expected_name: str) -> None:
project_manager = _create_project_manager()

local_path = project_manager.get_local_project_path(cloud_name, cloud_id=1)

assert local_path == Path.cwd() / expected_name
Loading