fix: decode base64 readme content as utf-8 instead of latin-1

atob() produces Latin-1 strings, mangling multi-byte UTF-8 characters
like box-drawing glyphs. Use TextDecoder for correct UTF-8 handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-05 16:28:40 +03:00
parent 1275a7785f
commit 0d350ce584

View File

@@ -75,6 +75,12 @@ export interface EventQuery {
const API_BASE = '/api/v1';
/** Decode base64 content as UTF-8 (atob only handles Latin-1). */
function decodeBase64Utf8(b64: string): string {
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
return new TextDecoder().decode(bytes);
}
export async function fetchEvents(q: EventQuery): Promise<TimelineItem[]> {
const params = new URLSearchParams();
if (q.from) params.set('from', q.from.toISOString());
@@ -109,7 +115,7 @@ export async function fetchReadme(source: Source, host: string, repo: string): P
if (!resp.ok) return null;
const data = await resp.json();
if (data.encoding === 'base64' && data.content) {
return atob(data.content);
return decodeBase64Utf8(data.content);
}
return data.content ?? null;
}
@@ -119,7 +125,7 @@ export async function fetchReadme(source: Source, host: string, repo: string): P
if (!resp.ok) continue;
const data = await resp.json();
if (data.encoding === 'base64' && data.content) {
return atob(data.content);
return decodeBase64Utf8(data.content);
}
if (data.content) return data.content;
}