summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/string.c b/string.c
index 7943465ef3..678b1b8802 100644
--- a/string.c
+++ b/string.c
@@ -684,6 +684,10 @@ rb_str_rindex(argc, argv, str)
if (rb_scan_args(argc, argv, "11", &sub, &position) == 2) {
pos = NUM2INT(position);
+ if (pos < 0) {
+ pos += RSTRING(str)->len;
+ if (pos < 0) return Qnil;
+ }
if (pos > RSTRING(str)->len) pos = RSTRING(str)->len;
}
else {