From 41d1b417e70d45d8e2fe3bb6c911c72adb77f20f Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 13 Jun 2024 19:23:51 +0000 Subject: [PATCH] avatars: Clean up now-irrelevant assumptions. This x=x hack was removed in 3bd3173b1f6dced6e35337323e5140b9fdaa1df4. --- zerver/views/upload.py | 7 ++++--- zerver/views/users.py | 7 ++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/zerver/views/upload.py b/zerver/views/upload.py index a33d74f715..b8393ab1b2 100644 --- a/zerver/views/upload.py +++ b/zerver/views/upload.py @@ -285,9 +285,10 @@ def serve_local_avatar_unauthed(request: HttpRequest, path: str) -> HttpResponse # We do not expect clients to hit this URL when using the S3 # backend; however, there is no reason to not serve the # redirect to S3 where the content lives. - return redirect( - get_public_upload_root_url() + path + "?" + request.GET.urlencode(), permanent=True - ) + url = get_public_upload_root_url() + path + if request.GET.urlencode(): + url += "?" + request.GET.urlencode() + return redirect(url, permanent=True) local_path = os.path.join(settings.LOCAL_AVATARS_DIR, path) assert_is_local_storage_path("avatars", local_path) diff --git a/zerver/views/users.py b/zerver/views/users.py index 0b1c1a0f89..773fe12f0b 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -312,12 +312,9 @@ def avatar( avatar_version = 1 url = get_gravatar_url(email, avatar_version, medium) - # We can rely on the URL already having query parameters. Because - # our templates depend on being able to use the ampersand to - # add query parameters to our url, get_avatar_url does '?x=x' - # hacks to prevent us from having to jump through decode/encode hoops. assert url is not None - url = append_url_query_string(url, request.META["QUERY_STRING"]) + if request.META["QUERY_STRING"]: + url = append_url_query_string(url, request.META["QUERY_STRING"]) return redirect(url)