Skip to content

Commit 346446b

Browse files
committed
fixes #36 fix bug in BM-prefix check when handling runes more than 16 bits.
1 parent f49f484 commit 346446b

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

regexp_test.go

+31-6
Original file line numberDiff line numberDiff line change
@@ -1093,27 +1093,23 @@ func TestEmptyCaptureLargeRepeat(t *testing.T) {
10931093
}
10941094
}
10951095

1096-
func TestFuzzBytes(t *testing.T) {
1096+
func TestFuzzBytes_NoCompile(t *testing.T) {
10971097
//some crash cases found from fuzzing
10981098

10991099
var testCases = []struct {
1100-
r, s []byte
1100+
r []byte
11011101
}{
11021102
{
11031103
r: []byte{0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
1104-
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
11051104
},
11061105
{
11071106
r: []byte{0x28, 0x5c, 0x32, 0x28, 0x3f, 0x28, 0x30, 0x29, 0x29},
1108-
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
11091107
},
11101108
{
11111109
r: []byte{0x28, 0x3f, 0x28, 0x29, 0x29, 0x5c, 0x31, 0x30, 0x28, 0x3f, 0x28, 0x30, 0x29},
1112-
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
11131110
},
11141111
{
11151112
r: []byte{0x28, 0x29, 0x28, 0x28, 0x29, 0x5c, 0x37, 0x28, 0x3f, 0x28, 0x29, 0x29},
1116-
s: []byte{0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
11171113
},
11181114
}
11191115

@@ -1129,3 +1125,32 @@ func TestFuzzBytes(t *testing.T) {
11291125
}
11301126

11311127
}
1128+
1129+
func TestFuzzBytes_Match(t *testing.T) {
1130+
1131+
var testCases = []struct {
1132+
r, s []byte
1133+
}{
1134+
{
1135+
r: []byte{0x30, 0xbf, 0x30, 0x2a, 0x30, 0x30},
1136+
s: []byte{0xf0, 0xb0, 0x80, 0x91, 0xf7},
1137+
},
1138+
{
1139+
r: []byte{0x30, 0xaf, 0xf3, 0x30, 0x2a},
1140+
s: []byte{0xf3, 0x80, 0x80, 0x87, 0x80, 0x89},
1141+
},
1142+
}
1143+
1144+
for _, c := range testCases {
1145+
r := string(c.r)
1146+
t.Run(r, func(t *testing.T) {
1147+
re, err := Compile(r, 0)
1148+
1149+
if err != nil {
1150+
t.Fatal("should compile, but didn't")
1151+
}
1152+
1153+
re.MatchString(string(c.s))
1154+
})
1155+
}
1156+
}

syntax/prefix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ func (b *BmPrefix) Scan(text []rune, index, beglimit, endlimit int) int {
712712

713713
if chTest != b.pattern[match] {
714714
advance = b.positive[match]
715-
if (chTest & 0xFF80) == 0 {
715+
if chTest < 128 {
716716
test2 = (match - startmatch) + b.negativeASCII[chTest]
717717
} else if chTest < 0xffff && len(b.negativeUnicode) > 0 {
718718
unicodeLookup = b.negativeUnicode[chTest>>8]

0 commit comments

Comments
 (0)