fix(validator): exclude the correct GBK trail byte (#372)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-23 20:54:08 +08:00
1 parent 65806afc7d
commit 129da3f2ed
2 files changed
+4 -1

No files matched your search

+1 -1
View File
@@ -505,7 +505,7 @@ func IsGBK(data []byte) bool {
i+1 < len(data) && i+1 < len(data) &&
data[i+1] >= 0x40 && data[i+1] >= 0x40 &&
data[i+1] <= 0xfe && data[i+1] <= 0xfe &&
data[i+1] != 0xf7 { data[i+1] != 0x7f {
i += 2 i += 2
continue continue
} else { } else {
+3
View File
@@ -811,6 +811,9 @@ func TestIsGBK(t *testing.T) {
t.Parallel() t.Parallel()
assert := internal.NewAssert(t, "TestIsGBK") assert := internal.NewAssert(t, "TestIsGBK")
if !IsGBK([]byte{0x81, 0xf7}) || IsGBK([]byte{0x81, 0x7f}) {
t.Error("GBK trails must allow 0xf7 and reject 0x7f")
}
str := "你好" str := "你好"
gbkData, _ := simplifiedchinese.GBK.NewEncoder().Bytes([]byte(str)) gbkData, _ := simplifiedchinese.GBK.NewEncoder().Bytes([]byte(str))