summaryrefslogtreecommitdiffstats
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
commitc49a3f37d7c1ae32c8c52421ac748e95c6f654a9 (patch)
treefe9b4ee30fad04c9f24b539174bc78b6dcbe9dcf
parent9dddfc2dc374838f1e728fe8eecd9f607f059b6e (diff)
downloadruby-c49a3f37d7c1ae32c8c52421ac748e95c6f654a9.tar.gz
ruby-c49a3f37d7c1ae32c8c52421ac748e95c6f654a9.tar.xz
ruby-c49a3f37d7c1ae32c8c52421ac748e95c6f654a9.zip
* string.c (rb_str_aref): "abc"[3] should not return an empty
string but nil. [ruby-dev:28786] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--string.c6
2 files changed, 11 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 5bdc6cdc1..a62b4fe4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/string.c b/string.c
index f254915f9..136235580 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: