From 3a5b593e0879f024192cb1df5ab47866c6c93320 Mon Sep 17 00:00:00 2001 From: Ishihara-exture Date: Wed, 3 Jun 2026 13:17:34 +0900 Subject: [PATCH] fix: decode UTF-8 text artifacts correctly in getTextContent() 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: https://github.com/google/adk-web/issues/452 --- src/app/components/artifact-tab/artifact-tab.component.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/components/artifact-tab/artifact-tab.component.ts b/src/app/components/artifact-tab/artifact-tab.component.ts index 05fd726b..190b3995 100644 --- a/src/app/components/artifact-tab/artifact-tab.component.ts +++ b/src/app/components/artifact-tab/artifact-tab.component.ts @@ -158,7 +158,11 @@ export class ArtifactTabComponent implements OnChanges { if (commaIndex === -1) return ''; const base64 = dataUrl.substring(commaIndex + 1); try { - return atob(base64); + // Use decodeURIComponent(escape(...)) to correctly reconstruct Unicode + // strings from UTF-8 byte sequences produced by renderArtifact()'s + // btoa(unescape(encodeURIComponent(text))) encoding. + // Plain atob() returns a Latin-1 string, causing garbled non-ASCII text. + return decodeURIComponent(escape(atob(base64))); } catch (e) { return 'Failed to decode text content'; }