@@ -467,7 +467,9 @@ func (r *regexpWrapper) findSubmatchIndexUnicode(s unicodeString, fullUnicode bo
posMap, runes, _, _ := buildPosMap(&lenientUtf16Decoder{utf16Reader: s.utf16Reader(0)}, s.length(), 0)
res := wrapped.FindReaderSubmatchIndex(&arrayRuneReader{runes: runes})
for i, item := range res {
- res[i] = posMap[item]
+ if item >= 0 {
+ res[i] = posMap[item]
+ }
}
return res
@@ -481,6 +481,14 @@ func TestRegexpOverrideSpecies(t *testing.T) {
testScript1(SCRIPT, _undefined, t)
+func TestRegexp2InvalidEscape(t *testing.T) {
+ testScript1(`/(?=)\x0/.test("x0")`, valueTrue, t)
+}
+
+func TestRegexpUnicodeEmptyMatch(t *testing.T) {
+ testScript1(`/(0)0|/gu.exec("0\xef").length === 2`, valueTrue, t)
func BenchmarkRegexpSplitWithBackRef(b *testing.B) {
const SCRIPT = `
"aaaaaaaaaaaaaaaaaaaaaaaaa++bbbbbbbbbbbbbbbbbbbbbb+-ccccccccccccccccccccccc".split(/([+-])\1/)