Skip to content

Commit fc77fca

Browse files
committed
display path
1 parent 3eacf30 commit fc77fca

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

services/storage/src/simcore_service_storage/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class PathMetaData(BaseModel):
369369
def update_display_fields(self, id_name_mapping: dict[str, str]) -> None:
370370
display_path = f"{self.path}"
371371
for old, new in id_name_mapping.items():
372-
display_path = display_path.replace(old, new)
372+
display_path = display_path.replace(old, urllib.parse.quote(new, safe=""))
373373
self.display_path = Path(display_path)
374374

375375
if self.file_meta_data:

services/storage/tests/unit/test_handlers_paths.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from collections.abc import Awaitable, Callable
1212
from pathlib import Path
1313
from typing import Any, TypeAlias
14+
from urllib.parse import quote
1415

1516
import httpx
1617
import pytest
@@ -387,16 +388,30 @@ async def test_list_paths_with_display_name_containing_slashes(
387388
sqlalchemy_async_engine: AsyncEngine,
388389
):
389390
project, list_of_files = with_random_project_with_files
390-
name_with_slashes = "something with/ a slash"
391+
project_name_with_slashes = "soméà$èq¨thing with/ slas/h/es/"
392+
node_name_with_non_ascii = "my node / is not ascii: éàèù"
393+
# adjust project to contain "difficult" characters
391394
async with sqlalchemy_async_engine.begin() as conn:
392395
result = await conn.execute(
393396
sa.update(projects)
394397
.where(projects.c.uuid == project["uuid"])
395-
.values(name=name_with_slashes)
396-
.returning(sa.literal_column(f"{projects.c.name}"))
398+
.values(name=project_name_with_slashes)
399+
.returning(sa.literal_column(f"{projects.c.name}, {projects.c.workbench}"))
397400
)
398401
row = result.one()
399-
assert row[0] == name_with_slashes
402+
assert row.name == project_name_with_slashes
403+
project_workbench = row.workbench
404+
assert len(project_workbench) == 1
405+
node = next(iter(project_workbench.values()))
406+
node["label"] = node_name_with_non_ascii
407+
result = await conn.execute(
408+
sa.update(projects)
409+
.where(projects.c.uuid == project["uuid"])
410+
.values(workbench=project_workbench)
411+
.returning(sa.literal_column(f"{projects.c.name}, {projects.c.workbench}"))
412+
)
413+
row = result.one()
414+
400415
# ls the root
401416
file_filter = None
402417
expected_paths = [(Path(project["uuid"]), False)]
@@ -410,10 +425,27 @@ async def test_list_paths_with_display_name_containing_slashes(
410425
expected_paths=expected_paths,
411426
)
412427

413-
assert page_of_paths.items[0].display_path == Path(name_with_slashes)
428+
assert page_of_paths.items[0].display_path == Path(
429+
quote(project_name_with_slashes, safe="")
430+
), "display path parts should be url encoded"
414431

432+
# ls the nodes to ensure / is still there between project and node
415433
file_filter = Path(project["uuid"])
416434
expected_paths = sorted(
417435
((file_filter / node_key, False) for node_key in project["workbench"]),
418436
key=lambda x: x[0],
419437
)
438+
assert len(expected_paths) == 1, "test configuration problem"
439+
page_of_paths = await _assert_list_paths(
440+
initialized_app,
441+
client,
442+
location_id,
443+
user_id,
444+
file_filter=file_filter,
445+
expected_paths=expected_paths,
446+
)
447+
assert page_of_paths.items[0].display_path == Path(
448+
quote(project_name_with_slashes, safe="")
449+
) / quote(
450+
node_name_with_non_ascii, safe=""
451+
), "display path parts should be url encoded"

0 commit comments

Comments
 (0)