diff --git a/internal/pkg/helper/exec/file.go b/internal/pkg/helper/exec/file.go index 2b31a797337cea947b99a7a40c9e85701a3499a5..b1a3fe5255e0f40da4478de0821a4443d26ad934 100644 --- a/internal/pkg/helper/exec/file.go +++ b/internal/pkg/helper/exec/file.go @@ -109,6 +109,7 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf, for { line, err2 := reader1.ReadString('\n') if line != "" { + line = stringUtils.Convert2Utf8IfNeeded(line) if commConsts.ExecFrom == commConsts.FromClient { websocketHelper.SendOutputMsg(line, "", iris.Map{"key": key}, wsMsg) logUtils.ExecConsole(-1, line) @@ -157,6 +158,7 @@ ExitCurrCase: if err2 != nil || io.EOF == err2 { break } + line = stringUtils.Convert2Utf8IfNeeded(line) errOutputArr = append(errOutputArr, line) } } diff --git a/pkg/lib/string/utf8.go b/pkg/lib/string/utf8.go new file mode 100644 index 0000000000000000000000000000000000000000..57ac15a1b3e74aed996382af224e3c0f70da3252 --- /dev/null +++ b/pkg/lib/string/utf8.go @@ -0,0 +1,16 @@ +package stringUtils + +import ( + "unicode/utf8" + + "golang.org/x/text/encoding/simplifiedchinese" +) + +func Convert2Utf8IfNeeded(data string) string { + if !utf8.Valid([]byte(data)) && IsGBK([]byte(data)) { + newLine, _ := simplifiedchinese.GBK.NewDecoder().Bytes([]byte(data)) + data = string(newLine) + } + + return data +}