diff options
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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; } |