From 5f7698c6b4a2c7477f34eea4ce6ea2940f857758 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Sun, 8 Jun 2025 09:28:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20improve=20Chinese=20character=20display?= =?UTF-8?q?=20in=20HTML=20reports=20-=20Fix=20JSON=20serialization=20to=20?= =?UTF-8?q?preserve=20Chinese=20characters=20instead=20of=20Unicode=20esca?= =?UTF-8?q?ping=20-=20Use=20SetEscapeHTML(false)=20in=20toJSON=20template?= =?UTF-8?q?=20function=20-=20Apply=20safeHTML=20to=20prevent=20HTML=20enti?= =?UTF-8?q?ty=20encoding=20of=20Chinese=20text=20-=20Now=20displays=20{"te?= =?UTF-8?q?xt":"=E8=BF=9E=E4=BA=86=E5=8F=88=E8=BF=9E"}=20instead=20of=20{&?= =?UTF-8?q?#34;text":"=E8=BF=9E=E4=BA=86=E5=8F=88=E8=BF=9E"}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/version/VERSION | 2 +- report.go | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index 6dfa4af5..67f81f2c 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2506080923 +v5.0.0-beta-2506080929 diff --git a/report.go b/report.go index 98833858..0fd30978 100644 --- a/report.go +++ b/report.go @@ -237,11 +237,18 @@ func (g *HTMLReportGenerator) GenerateReport(outputFile string) error { "encodeImageBase64": g.encodeImageToBase64, "getStepLogs": g.getStepLogsForTemplate, "safeHTML": func(s string) template.HTML { return template.HTML(s) }, - "toJSON": func(v interface{}) string { b, _ := json.Marshal(v); return string(b) }, - "mul": func(a, b float64) float64 { return a * b }, - "add": func(a, b int) int { return a + b }, - "base": filepath.Base, - "index": func(m map[string]any, key string) interface{} { return m[key] }, + "toJSON": func(v interface{}) string { + var buf strings.Builder + encoder := json.NewEncoder(&buf) + encoder.SetEscapeHTML(false) + _ = encoder.Encode(v) + result := buf.String() + return strings.TrimSpace(result) + }, + "mul": func(a, b float64) float64 { return a * b }, + "add": func(a, b int) int { return a + b }, + "base": filepath.Base, + "index": func(m map[string]any, key string) interface{} { return m[key] }, } // Parse template @@ -1033,7 +1040,7 @@ const htmlTemplate = ` {{end}} {{if $subAction.Arguments}} -
Arguments: {{toJSON $subAction.Arguments}}
+
Arguments: {{safeHTML (toJSON $subAction.Arguments)}}
{{end}} {{if $subAction.Requests}} @@ -1143,7 +1150,7 @@ const htmlTemplate = `
{{$logEntry.Message}}
{{if $logEntry.Data}} -
{{toJSON $logEntry.Data}}
+
{{safeHTML (toJSON $logEntry.Data)}}
{{end}} {{end}}