mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
b77a4e2a4e
commit
66de9ef349
2 changed files with 11 additions and 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.
|
||||
|
|
6
string.c
6
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:
|
||||
|
|
Loading…
Reference in a new issue