From a6645e3340e9cca2597344cf484a01b4c5854682 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:10:31 +0800 Subject: [PATCH] fix: Chinese characters are incorrectly recognized as binary. #50 --- backend/utils/string/convert.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/utils/string/convert.go b/backend/utils/string/convert.go index d2a06c7..72e5caf 100644 --- a/backend/utils/string/convert.go +++ b/backend/utils/string/convert.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "tinyrdm/backend/types" + "unicode/utf8" ) // ConvertTo convert string to specified type @@ -175,10 +176,17 @@ func autoToType(str string) (value, resultType string) { } func isBinary(str string) bool { - for _, s := range str { - if s < 0x20 || s > 0x7E { - return true - } + //buf := []byte(str) + //size := 0 + //for start := 0; start < len(buf); start += size { + // var r rune + // if r, size = utf8.DecodeRune(buf[start:]); r == utf8.RuneError { + // return true + // } + //} + + if !utf8.ValidString(str) { + return true } return false }