summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-22 01:39:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-22 01:39:44 +0000
commit66de9ef3496793095176fb9cfa12480d7386b379 (patch)
treefe9b4ee30fad04c9f24b539174bc78b6dcbe9dcf /string.c
parentb77a4e2a4eeec6e5b55a0a8a662eff05f1f0a326 (diff)
* string.c (rb_str_aref): "abc"[3] should not return an empty
string but nil. [ruby-dev:28786] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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: