summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c14
1 files changed, 12 insertions, 2 deletions
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;
}