fix: isPrintable incorrect (#5076)

* fix: isPrintable incorrect

* fix: isPrintable incorrect

* style: use ReplaceAll instead of Replace
This commit is contained in:
li-jin-gou 2022-02-15 20:32:03 +08:00 committed by GitHub
parent a0aceeb33e
commit 19ac396a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -19,9 +19,9 @@ const (
nullStr = "NULL" nullStr = "NULL"
) )
func isPrintable(s []byte) bool { func isPrintable(s string) bool {
for _, r := range s { for _, r := range s {
if !unicode.IsPrint(rune(r)) { if !unicode.IsPrint(r) {
return false return false
} }
} }
@ -84,8 +84,8 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
} }
} }
case []byte: case []byte:
if isPrintable(v) { if s := string(v); isPrintable(s) {
vars[idx] = escaper + strings.Replace(string(v), escaper, "\\"+escaper, -1) + escaper vars[idx] = escaper + strings.ReplaceAll(s, escaper, "\\"+escaper) + escaper
} else { } else {
vars[idx] = escaper + "<binary>" + escaper vars[idx] = escaper + "<binary>" + escaper
} }