Skip to content

fix: decode UTF-8 text artifacts correctly in getTextContent()#453

Open
Ishihara-exture wants to merge 1 commit into
google:mainfrom
Ishihara-exture:fix/text-artifact-garbled-encoding
Open

fix: decode UTF-8 text artifacts correctly in getTextContent()#453
Ishihara-exture wants to merge 1 commit into
google:mainfrom
Ishihara-exture:fix/text-artifact-garbled-encoding

Conversation

@Ishihara-exture

Copy link
Copy Markdown

Summary

  • getTextContent() in artifact-tab.component.ts used atob(base64) which returns a Latin-1 byte string, causing non-ASCII characters (Japanese, Chinese, Korean, etc.) to appear garbled in the Artifacts tab preview and inline chat bubble.
  • renderArtifact() encodes text via btoa(unescape(encodeURIComponent(text))) (standard UTF-8 → base64 pattern), but the decode side was missing the reverse step.
  • Fix: replace atob(base64) with decodeURIComponent(escape(atob(base64))).

Test plan

  • Save a text artifact containing non-ASCII characters (e.g. "こんにちは") via Part.from_text()
  • Verify the Artifacts tab preview displays the original text correctly
  • Verify the inline chat bubble displays the original text correctly

Fixes #452

atob() returns a Latin-1 byte string, which garbles non-ASCII characters
(e.g. Japanese) when renderArtifact() encodes text via
btoa(unescape(encodeURIComponent(text))).

Replace atob(base64) with decodeURIComponent(escape(atob(base64))) to
correctly reconstruct the original Unicode string.

Fixes: google#452
@google-cla

google-cla Bot commented Jun 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Text artifact preview renders garbled characters for non-ASCII (multibyte) content

2 participants