فهرست منبع

Fixed handling of empty submatches in unicode strings. Fixes #210

Dmitry Panov 5 سال پیش
والد
کامیت
f97e50db25
2فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 3 1
      regexp.go
  2. 8 0
      regexp_test.go

+ 3 - 1
regexp.go

@@ -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
 	}

+ 8 - 0
regexp_test.go

@@ -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/)