From 775bc71e881b6a047fa3dd406030ecc71fbf5534 Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Wed, 9 Oct 2024 18:46:37 +0100 Subject: [PATCH] Revert "Allow spaces in avatar filenames. Fixes #1370. (#1418)" This reverts commit 970bde2b46331901716351f6082eace80c2bba0b. --- backend/chainlit/server.py | 2 +- backend/tests/test_server.py | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/backend/chainlit/server.py b/backend/chainlit/server.py index 64f48490b1..a980fae605 100644 --- a/backend/chainlit/server.py +++ b/backend/chainlit/server.py @@ -961,7 +961,7 @@ async def get_logo(theme: Optional[Theme] = Query(Theme.light)): @router.get("/avatars/{avatar_id:str}") async def get_avatar(avatar_id: str): """Get the avatar for the user based on the avatar_id.""" - if not re.match(r"^[a-zA-Z0-9_ -]+$", avatar_id): + if not re.match(r"^[a-zA-Z0-9_-]+$", avatar_id): raise HTTPException(status_code=400, detail="Invalid avatar_id") if avatar_id == "default": diff --git a/backend/tests/test_server.py b/backend/tests/test_server.py index 91b152030f..6e98bca782 100644 --- a/backend/tests/test_server.py +++ b/backend/tests/test_server.py @@ -174,24 +174,6 @@ def test_get_avatar_custom(test_client: TestClient, monkeypatch: pytest.MonkeyPa os.remove(custom_avatar_path) -def test_get_avatar_with_spaces( - test_client: TestClient, monkeypatch: pytest.MonkeyPatch -): - """Test with custom avatar.""" - custom_avatar_path = os.path.join(APP_ROOT, "public", "avatars", "my_assistant.png") - os.makedirs(os.path.dirname(custom_avatar_path), exist_ok=True) - with open(custom_avatar_path, "wb") as f: - f.write(b"fake image data") - - response = test_client.get("/avatars/My Assistant") - assert response.status_code == 200 - assert response.headers["content-type"].startswith("image/") - assert response.content == b"fake image data" - - # Clean up - os.remove(custom_avatar_path) - - def test_get_avatar_non_existent_favicon( test_client: TestClient, monkeypatch: pytest.MonkeyPatch ):