ext/re2/re2.cc in re2-0.4.0 vs ext/re2/re2.cc in re2-0.5.0
- old
+ new
@@ -175,15 +175,20 @@
{
re2_matchdata *m;
re2::StringPiece match;
Data_Get_Struct(self, re2_matchdata, m);
- match = m->matches[nth];
- if (nth >= m->number_of_matches || match.empty()) {
+ if (nth < 0 || nth >= m->number_of_matches) {
return Qnil;
} else {
- return rb_str_new(match.data(), match.size());
+ match = m->matches[nth];
+
+ if (match.empty()) {
+ return Qnil;
+ } else {
+ return rb_str_new(match.data(), match.size());
+ }
}
}
static VALUE
re2_matchdata_named_match(const char* name, VALUE self)