Skip to content

Commit

Permalink
chore(avatars): use urlencode to build URL
Browse files Browse the repository at this point in the history
This is simpler than quoting the parts manually.
  • Loading branch information
nijel committed Feb 14, 2025
1 parent 16a728a commit 873d7f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions weblate/accounts/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
from ssl import CertificateError
from typing import TYPE_CHECKING
from urllib.parse import quote
from urllib.parse import urlencode

from django.conf import settings
from django.contrib.staticfiles import finders
Expand All @@ -31,7 +31,9 @@ def avatar_for_email(email, size=80) -> str:

mail_hash = hashlib.md5(email.lower().encode(), usedforsecurity=False).hexdigest()

return f"{settings.AVATAR_URL_PREFIX}avatar/{mail_hash}?d={quote(settings.AVATAR_DEFAULT_IMAGE)}&s={size!s}"
querystring = urlencode({"d": settings.AVATAR_DEFAULT_IMAGE, "s": str(size)})

return f"{settings.AVATAR_URL_PREFIX}avatar/{mail_hash}?{querystring}"


def get_fallback_avatar_url(size: int):
Expand Down

0 comments on commit 873d7f5

Please sign in to comment.