Skip to content

Commit b93eddc

Browse files
committed
prevent panic when using 2-byte unicode bmPrefix against 3-byte input values. fixes #5
1 parent 4009c9d commit b93eddc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

regexp_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,17 @@ func TestECMANegateRange(t *testing.T) {
736736
}
737737
}
738738

739+
func TestThreeByteUnicode_InputOnly(t *testing.T) {
740+
// confirm the bmprefix properly ignores 3-byte unicode in the input value
741+
// this used to panic
742+
re := MustCompile("高", 0)
743+
if m, err := re.MatchString("📍Test高"); err != nil {
744+
t.Fatal(err)
745+
} else if !m {
746+
t.Fatal("Expected match")
747+
}
748+
}
749+
739750
/*
740751
func TestPcreStuff(t *testing.T) {
741752
re := MustCompile(`(?(?=(a))a)`, Debug)

syntax/prefix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ func (b *BmPrefix) Scan(text []rune, index, beglimit, endlimit int) int {
666666
if chTest != chMatch {
667667
if chTest < 128 {
668668
advance = b.negativeASCII[chTest]
669-
} else if nil != b.negativeUnicode {
669+
} else if chTest < 0xffff && len(b.negativeUnicode) > 0 {
670670
unicodeLookup = b.negativeUnicode[chTest>>8]
671-
if unicodeLookup != nil {
671+
if len(unicodeLookup) > 0 {
672672
advance = unicodeLookup[chTest&0xFF]
673673
} else {
674674
advance = defadv

0 commit comments

Comments
 (0)