Permalink
Browse files

Regexp.last_match(nth) should return nil if passed index which is out…

… of matched range

Here is code which expected that Regexp.last_match returns nil:

    /(...)/.match("foobarbaz")
    Regexp.last_match(4)  #=> nil
    Regexp.last_match(-3) #=> nil

However, raises an IndexError.
  • Loading branch information...
1 parent f7c0def commit b43448aeb6b0f045879592c0fb5d1e60581483c3 @Watson1978 Watson1978 committed Sep 5, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 re.c
View
2 re.c
@@ -514,7 +514,7 @@ regexp_last_match(VALUE klass, SEL sel, int argc, VALUE *argv)
if (NIL_P(match)) {
return Qnil;
}
- const int n = match_backref_number(match, nth, true);
+ const int n = match_backref_number(match, nth, false);
return rb_reg_nth_match(n, match);
}
return match_getter();

0 comments on commit b43448a

Please sign in to comment.