Skip to content

Commit dfd1cfb

Browse files
committed
fix use of constants in formatInvalidByteForError
1 parent 2358991 commit dfd1cfb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sql/types/strings.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545

4646
// Constants for charset validation
4747
asciiMax = 127
48+
asciiMin = 32
4849
invalidByteFormat = "\\x%02X"
4950
fallbackInvalidByte = "\\x00"
5051
)
@@ -582,12 +583,12 @@ func formatInvalidByteForError(bytesVal []byte) string {
582583

583584
// MySQL shows valid ASCII characters as their actual characters,
584585
// but invalid UTF-8 bytes (> 127) or control characters as hex
585-
if b >= 32 && b <= 126 {
586+
if b >= asciiMin && b <= asciiMax {
586587
// Printable ASCII character - show as character
587588
result.WriteByte(b)
588589
} else {
589590
// Invalid UTF-8 byte or control character - show as hex
590-
result.WriteString(fmt.Sprintf("\\x%02X", b))
591+
result.WriteString(fmt.Sprintf(invalidByteFormat, b))
591592
}
592593
}
593594

0 commit comments

Comments
 (0)