aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/string.c b/string.c
index f254915f9b..136235580c 100644
--- a/string.c
+++ b/string.c
@@ -1478,6 +1478,12 @@ rb_str_aref(VALUE str, VALUE indx)
idx = FIX2LONG(indx);
num_index:
+ if (idx < 0) {
+ idx = RSTRING(str)->len + idx;
+ }
+ if (idx < 0 || RSTRING(str)->len <= idx) {
+ return Qnil;
+ }
return rb_str_substr(str, idx, 1);
case T_REGEXP: