Skip to content

Commit

Permalink
fix: Chinese characters are incorrectly recognized as binary. tiny-cr…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Oct 9, 2023
1 parent ca663d8 commit a6645e3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions backend/utils/string/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"tinyrdm/backend/types"
"unicode/utf8"
)

// ConvertTo convert string to specified type
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a6645e3

Please sign in to comment.