Skip to content

Commit

Permalink
Revert "Allow spaces in avatar filenames. Fixes #1370. (#1418)"
Browse files Browse the repository at this point in the history
This reverts commit 970bde2.
  • Loading branch information
dokterbob committed Oct 9, 2024
1 parent 440e1d6 commit 775bc71
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
2 changes: 1 addition & 1 deletion backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
18 changes: 0 additions & 18 deletions backend/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down

0 comments on commit 775bc71

Please sign in to comment.