Repository: wagtail/wagtail
File: wagtail/users/utils.py (Python)

Code before:
    )
    Note: If any parameter in `default_params` also exists in the provider URL,
    It will be overridden by the provider URL's query parameter.
    ```
    """

    DEFAULT_GRAVATAR_PROVIDER_URL = "//www.gravatar.com/avatar"

    params = {
        **default_params,
        # requested at retina size by default and scaled down at point of use with css
        "s": int(size) * 2,
    }

    gravatar_provider_url = getattr(
        settings, "WAGTAIL_GRAVATAR_PROVIDER_URL", DEFAULT_GRAVATAR_PROVIDER_URL
    )

    if (not email) or (gravatar_provider_url is None):
        return None

    parsed_url = urlparse(gravatar_provider_url)

    if parsed_url.query:
        parsed_qs = parse_qs(parsed_url.query)
        parsed_qs.pop("s", None)
        parsed_qs.pop("size", None)
        params.update(parsed_qs)

    email_hash = safe_md5(
        email.lower().encode("utf-8"), usedforsecurity=False
    ).hexdigest()

    parsed_url = parsed_url._replace(
        path=f"{parsed_url.path.rstrip('/')}/{email_hash}",
        query=urlencode(params, doseq=True),
    )

    gravatar_url = urlunparse(parsed_url)

    return gravatar_url


def get_deleted_user_display_name(user_id):
    # Use a string placeholder as the user id could be non-numeric
    return _("user %(id)s (deleted)") % {"id": user_id}


Review comment (bug):
Let's keep this simple, just prepare the params in one go, if there's no qs to parse, just parse an empty string.

No need to pop/remove `s` this way.

Do not worry about the size edge case, if the developer really wants to use `size`, they will probably know what they are doing and want to do it intentionally.

```suggestion
    params = {
        **default_params,
        **(parse_qs(parsed_url.query or '')),
        # requested at retina size by default and scaled down at point of use with css
        "s": int(size) * 2,
    }

```

Code after:
            'user@example.com',
            size=100,
            default_params={'d': 'robohash', 'f': 'y'}
        )

    Note:
        If any parameter in ``default_params`` also exists in the provider URL,
        it will be overridden by the provider URL's query parameter.
    """

    gravatar_provider_url = getattr(
        settings, "WAGTAIL_GRAVATAR_PROVIDER_URL", "//www.gravatar.com/avatar"
    )

    if (not email) or (gravatar_provider_url is None):
        return None

    parsed_url = urlparse(gravatar_provider_url)

    params = {
        **default_params,
        **(parse_qs(parsed_url.query or "")),
        # requested at retina size by default and scaled down at point of use with css
        "s": int(size) * 2,
    }

    email_hash = safe_md5(
        email.lower().encode("utf-8"), usedforsecurity=False
    ).hexdigest()

    parsed_url = parsed_url._replace(
        path=f"{parsed_url.path.rstrip('/')}/{email_hash}",
        query=urlencode(params, doseq=True),
    )

    gravatar_url = urlunparse(parsed_url)

    return gravatar_url


def get_deleted_user_display_name(user_id):
    # Use a string placeholder as the user id could be non-numeric
    return _("user %(id)s (deleted)") % {"id": user_id}