From 9c906934fdeccf1c99a68be385ea999d07d79f04 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Tue, 10 Jun 2025 17:07:08 +0800 Subject: [PATCH] fix: resolve Chinese character encoding issue in HTML report downloads - Add decodeBase64UTF8 function to properly handle UTF-8 encoded Base64 content - Replace atob() with TextDecoder for correct Chinese character decoding - Explicitly specify UTF-8 charset when creating download Blob - Fix garbled Chinese text when downloading summary.json from HTML report --- internal/version/VERSION | 2 +- report.go | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index 1d1e0f38..fd2338ac 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2506101640 +v5.0.0-beta-2506101707 diff --git a/report.go b/report.go index 632b98f8..302ffb5e 100644 --- a/report.go +++ b/report.go @@ -2409,9 +2409,25 @@ const htmlTemplate = ` const summaryContentBase64 = "{{getSummaryContentBase64}}"; const logContentBase64 = "{{getLogContentBase64}}"; - // Decode Base64 content - const summaryContent = summaryContentBase64 ? atob(summaryContentBase64) : ""; - const logContent = logContentBase64 ? atob(logContentBase64) : ""; + // Decode Base64 content with proper UTF-8 handling + function decodeBase64UTF8(base64) { + if (!base64) return ""; + try { + // Use TextDecoder for proper UTF-8 decoding + const binaryString = atob(base64); + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + return new TextDecoder('utf-8').decode(bytes); + } catch (e) { + console.error('Failed to decode Base64 content:', e); + return ""; + } + } + + const summaryContent = decodeBase64UTF8(summaryContentBase64); + const logContent = decodeBase64UTF8(logContentBase64); // Download functions function downloadSummary() { @@ -2431,7 +2447,7 @@ const htmlTemplate = ` } function downloadFile(content, filename, mimeType) { - const blob = new Blob([content], { type: mimeType }); + const blob = new Blob([content], { type: mimeType + ';charset=utf-8' }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url;