Skip to content

fix: encode inline SVG avatars as UTF-8 in getEnsAvatar - #5250

Merged
jxom merged 2 commits into
wevm:mainfrom
RaphaelFakhri:fix/ens-avatar-svg-utf8
Oct 24, 2026
Merged

jxom merged 2 commits into
wevm:mainfrom
RaphaelFakhri:fix/ens-avatar-svg-utf8

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

resolveAvatarUri encodes inline SVG avatars with btoa, which throws InvalidCharacterError for any character outside Latin-1. As a result, getEnsAvatar returns null for SVG avatars that contain text like é or emoji, including ERC-721 metadata whose image_data is an inline SVG.

Fixes #5249

Changes

  • Encode inline SVGs with Base64.fromString from ox, which encodes the UTF-8 bytes.
  • Decode data:application/json;base64, NFT metadata with Base64.toString instead of atob. atob returns Latin-1, which only worked before because btoa re-encoded the same bytes. With a UTF-8 encoder, keeping atob would double-encode non-ASCII metadata.

Tests

  • resolveAvatarUri: inline SVG with café ⚡. Fails on main with Invalid character.
  • parseAvatarRecord: ERC-721 tokenURI as raw JSON with a UTF-8 image_data SVG (token 110 in EnsAvatarTokenUri). Fails on main with Invalid character.
  • parseAvatarRecord: the same metadata as base64 JSON (token 109). Passes on main and guards the decoder change; it fails if only the encoder is changed.

@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@RaphaelFakhri is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

jxom commented Oct 22, 2026

Copy link
Copy Markdown
Member

Thanks, looks good. One regression: atob ignores whitespace, but Base64.toString doesn't, so base64 metadata with a newline (e.g. a trailing \n) now decodes to garbage and getEnsAvatar returns null.

Suggested fix in parseAvatarRecord.ts:

Base64.toString(
  resolvedNftUri
    .replace('data:application/json;base64,', '')
    .replace(/\s/g, ''),
)

Plus a fixture token returning the token 109 payload with a newline in the middle and at the end, with the same expected snapshot.


Generated by Claude Code

@RaphaelFakhri

RaphaelFakhri commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. The latest push strips whitespace before decoding and adds a token 111 fixture with a newline in the middle and at the end. It expects the same snapshot as token 109.

@changeset-bot

changeset-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4799112

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jxom
jxom merged commit 2d54066 into wevm:main Oct 24, 2026
2 of 3 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getEnsAvatar returns null for inline SVG avatars that contain non-Latin-1 text

2 participants