mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 17:44:02 +08:00
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:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2506101640
|
||||
v5.0.0-beta-2506101707
|
||||
|
||||
24
report.go
24
report.go
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user