diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-07 04:34:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-07 04:34:34 +0000 |
commit | e895bc3cdb71eb950951f6a7b7ce70bcb2ae9022 (patch) | |
tree | 3c57971c07372421166c18c035036508e0a35bc5 | |
parent | 9041ac4289cc88751d4d7d492f0402c13fac3057 (diff) |
* enum.c (rb_enum_join): non-nil separator must be convertible to
String. [ruby-core:24172]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enum.c | 1 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 9 |
3 files changed, 15 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Jul 7 13:34:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * enum.c (rb_enum_join): non-nil separator must be convertible to + String. [ruby-core:24172] + Tue Jul 7 12:47:28 2009 Yukihiro Matsumoto <matz@ruby-lang.org> * enum.c (rb_enum_join): should propagate taint to the return @@ -1828,6 +1828,7 @@ rb_enum_join(VALUE obj, VALUE sep) args[0] = 0; args[1] = sep; + if (!NIL_P(sep)) StringValue(args[1]); rb_block_call(obj, id_each, 0, 0, join_i, (VALUE)args); if (!args[0]) args[0] = rb_str_new(0, 0); OBJ_INFECT(args[0], obj); diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 6f27c5b826..e0e77b4869 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -285,8 +285,15 @@ class TestEnumerable < Test::Unit::TestCase end def test_join + ofs = $, assert_equal("abc", ("a".."c").join("")) assert_equal("a-b-c", ("a".."c").join("-")) + $, = "-" + assert_equal("a-b-c", ("a".."c").join()) + $, = nil + assert_equal("abc", ("a".."c").join()) + assert_equal("123", (1..3).join()) + assert_raise(TypeError, '[ruby-core:24172]') {("a".."c").join(1)} class << (e = Object.new.extend(Enumerable)) def to_s "e" @@ -296,5 +303,7 @@ class TestEnumerable < Test::Unit::TestCase end end assert_equal("e", e.join("")) + ensure + $, = ofs end end |