ruby-changes:37614
From: nobu <ko1@a...>
Date: Mon, 23 Feb 2015 15:27:01 +0900 (JST)
Subject: [ruby-changes:37614] nobu:r49695 (trunk): string.c: proper exception
nobu 2015-02-23 15:26:42 +0900 (Mon, 23 Feb 2015) New Revision: 49695 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49695 Log: string.c: proper exception * string.c (rb_str_split_m): raise ArgumentError at broken string not RegexpError, as Regexp is not involved in. [ruby-core:68229] [Bug #10886] Modified files: trunk/ChangeLog trunk/string.c trunk/test/ruby/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49694) +++ ChangeLog (revision 49695) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Feb 23 15:26:39 2015 Nobuyoshi Nakada <nobu@r...> + + * string.c (rb_str_split_m): raise ArgumentError at broken string + not RegexpError, as Regexp is not involved in. + [ruby-core:68229] [Bug #10886] + Mon Feb 23 07:25:29 2015 Benoit Daloze <eregontp@g...> * time.c: Zone encoding should be US-ASCII if all 7-bits. Fix r46907. Index: string.c =================================================================== --- string.c (revision 49694) +++ string.c (revision 49695) @@ -6387,10 +6387,11 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L6387 } else { fs_set: - spat = get_pat_quoted(spat, 1); + spat = get_pat_quoted(spat, 0); if (BUILTIN_TYPE(spat) == T_STRING) { rb_encoding *enc2 = STR_ENC_GET(spat); + mustnot_broken(spat); split_type = string; if (RSTRING_LEN(spat) == 0) { /* Special case - split into chars */ @@ -6485,7 +6486,6 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L6486 long slen = RSTRING_LEN(spat); mustnot_broken(str); - mustnot_broken(spat); enc = rb_enc_check(str, spat); while (ptr < eptr && (end = rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) { Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 49694) +++ test/ruby/test_string.rb (revision 49695) @@ -1345,14 +1345,18 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1345 assert_equal([], "".split(//, 1)) assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug") + end + def test_split_encoding bug6206 = '[ruby-dev:45441]' Encoding.list.each do |enc| next unless enc.ascii_compatible? s = S("a:".force_encoding(enc)) assert_equal([enc]*2, s.split(":", 2).map(&:encoding), bug6206) end + end + def test_split_wchar bug8642 = '[ruby-core:56036] [Bug #8642]' [ Encoding::UTF_16BE, Encoding::UTF_16LE, @@ -1365,6 +1369,20 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1369 end end + def test_split_invalid_sequence + bug10886 = '[ruby-core:68229] [Bug #10886]' + broken = S("\xa1".force_encoding("utf-8")) + assert_raise(ArgumentError, bug10886) { + S("a,b").split(broken) + } + end + + def test_split_invalid_argument + assert_raise(TypeError) { + S("a,b").split(BasicObject.new) + } + end + def test_squeeze assert_equal(S("abc"), S("aaabbbbccc").squeeze) assert_equal(S("aa bb cc"), S("aa bb cc").squeeze(S(" "))) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/