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
This commit is contained in:
lilong.129
2025-06-10 17:07:08 +08:00
parent 98bd41ff33
commit 9c906934fd
2 changed files with 21 additions and 5 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2506101640
v5.0.0-beta-2506101707

View File

@@ -2409,9 +2409,25 @@ const htmlTemplate = `<!DOCTYPE html>
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 = `<!DOCTYPE html>
}
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;