From 19ac396a22668e2cdbd77a262de84478787989d0 Mon Sep 17 00:00:00 2001 From: li-jin-gou <97824201+li-jin-gou@users.noreply.github.com> Date: Tue, 15 Feb 2022 20:32:03 +0800 Subject: [PATCH] fix: isPrintable incorrect (#5076) * fix: isPrintable incorrect * fix: isPrintable incorrect * style: use ReplaceAll instead of Replace --- logger/sql.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logger/sql.go b/logger/sql.go index e0be57c0..04a2dbd4 100644 --- a/logger/sql.go +++ b/logger/sql.go @@ -19,9 +19,9 @@ const ( nullStr = "NULL" ) -func isPrintable(s []byte) bool { +func isPrintable(s string) bool { for _, r := range s { - if !unicode.IsPrint(rune(r)) { + if !unicode.IsPrint(r) { return false } } @@ -84,8 +84,8 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a } } case []byte: - if isPrintable(v) { - vars[idx] = escaper + strings.Replace(string(v), escaper, "\\"+escaper, -1) + escaper + if s := string(v); isPrintable(s) { + vars[idx] = escaper + strings.ReplaceAll(s, escaper, "\\"+escaper) + escaper } else { vars[idx] = escaper + "" + escaper }