mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(validator): exclude the correct GBK trail byte (#372)
This commit is contained in:
1 parent
65806afc7d
commit
129da3f2ed
2 files changed
+4
-1
No files matched your search
@@ -505,7 +505,7 @@ func IsGBK(data []byte) bool {
|
||||
i+1 < len(data) &&
|
||||
data[i+1] >= 0x40 &&
|
||||
data[i+1] <= 0xfe &&
|
||||
data[i+1] != 0xf7 {
|
||||
data[i+1] != 0x7f {
|
||||
i += 2
|
||||
continue
|
||||
} else {
|
||||
|
||||
@@ -811,6 +811,9 @@ func TestIsGBK(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
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 := "你好"
|
||||
gbkData, _ := simplifiedchinese.GBK.NewEncoder().Bytes([]byte(str))
|
||||
|
||||
Reference in new issue
Block a user