@@ -1058,3 +1058,37 @@ func TestBadGroupConstruct(t *testing.T) {
10581058 }
10591059 }
10601060}
1061+
1062+ func TestEmptyCaptureLargeRepeat (t * testing.T ) {
1063+ // a bug would cause our track to not grow and eventually panic
1064+ // with large numbers of repeats of a non-capturing group (>16)
1065+
1066+ // the issue was that the jump occured to the same statement over and over
1067+ // and the "grow stack/track" logic only triggered on jumps that moved
1068+ // backwards
1069+
1070+ r := MustCompile (`(?:){40}` , 0 )
1071+ m , err := r .FindStringMatch ("1" )
1072+ if err != nil {
1073+ t .Fatalf ("Unexpected error: %v" , err )
1074+ }
1075+ if want , got := 0 , m .Index ; want != got {
1076+ t .Errorf ("First Match Index wanted %v got %v" , want , got )
1077+ }
1078+ if want , got := 0 , m .Length ; want != got {
1079+ t .Errorf ("First Match Length wanted %v got %v" , want , got )
1080+ }
1081+
1082+ m , _ = r .FindNextMatch (m )
1083+ if want , got := 1 , m .Index ; want != got {
1084+ t .Errorf ("Second Match Index wanted %v got %v" , want , got )
1085+ }
1086+ if want , got := 0 , m .Length ; want != got {
1087+ t .Errorf ("Second Match Length wanted %v got %v" , want , got )
1088+ }
1089+
1090+ m , _ = r .FindNextMatch (m )
1091+ if m != nil {
1092+ t .Fatal ("Expected 2 matches, got more" )
1093+ }
1094+ }
0 commit comments