From 6d2e56ce7c3e7e53745105ed2d1011e522bcbbbe Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 19 Mar 2002 09:03:11 +0000 Subject: * re.c (rb_reg_search): should clear last_match if pos is out of string range. * string.c (rb_str_index_m): ditto. * string.c (rb_str_rindex): ditto. * class.c (rb_define_class): should handle autoload. * class.c (rb_define_module): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 41d697bce0..72a1783aa8 100644 --- a/string.c +++ b/string.c @@ -887,7 +887,12 @@ rb_str_index_m(argc, argv, str) } if (pos < 0) { pos += RSTRING(str)->len; - if (pos < 0) return Qnil; + if (pos < 0) { + if (TYPE(sub) == T_REGEXP) { + rb_backref_set(Qnil); + } + return Qnil; + } } switch (TYPE(sub)) { @@ -936,7 +941,12 @@ rb_str_rindex(argc, argv, str) pos = NUM2INT(position); if (pos < 0) { pos += RSTRING(str)->len; - if (pos < 0) return Qnil; + if (pos < 0) { + if (TYPE(sub) == T_REGEXP) { + rb_backref_set(Qnil); + } + return Qnil; + } } if (pos > RSTRING(str)->len) pos = RSTRING(str)->len; } -- cgit v1.2.3