diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 6 |
2 files changed, 11 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Thu Jun 22 10:31:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (rb_str_aref): "abc"[3] should not return an empty + string but nil. [ruby-dev:28786] + Thu Jun 22 05:15:58 2006 Tanaka Akira <akr@m17n.org> * ext/socket/socket.c (sock_s_socketpair): try GC only once. @@ -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: |