Skip to content

Commit 7f46e8e

Browse files
elianddbclaude
andcommitted
Address PR review comments for charset validation
1. Explicitly specify utf8mb4 charset for test table columns instead of relying on defaults 2. Fix formatInvalidByteForError to properly detect invalid UTF-8 sequences using utf8.DecodeRune instead of incorrect byte > 127 check 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 12324f5 commit 7f46e8e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

enginetest/queries/script_queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7167,7 +7167,7 @@ where
71677167
{
71687168
Name: "charset validation strict vs non-strict mode",
71697169
SetUpScript: []string{
7170-
"create table charset_test (c char(10), v varchar(10), txt text);",
7170+
"create table charset_test (c char(10) character set utf8mb4, v varchar(10) character set utf8mb4, txt text character set utf8mb4);",
71717171
},
71727172
Assertions: []ScriptTestAssertion{
71737173
{

sql/types/strings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,13 @@ func formatInvalidByteForError(bytesVal []byte) string {
557557

558558
// Find the first invalid UTF-8 position
559559
firstInvalidPos := -1
560-
for i, b := range bytesVal {
561-
if b > asciiMax {
560+
for i := 0; i < len(bytesVal); {
561+
r, size := utf8.DecodeRune(bytesVal[i:])
562+
if r == utf8.RuneError && size == 1 {
562563
firstInvalidPos = i
563564
break
564565
}
566+
i += size
565567
}
566568

567569
// If no invalid bytes found, but we're here due to invalid UTF-8,

0 commit comments

Comments
 (0)