ruby-changes:33004
From: naruse <ko1@a...>
Date: Fri, 21 Feb 2014 23:53:56 +0900 (JST)
Subject: [ruby-changes:33004] naruse:r45083 (ruby_2_1): merge revision(s) 44462, 44477: [Backport #9314]
naruse 2014-02-21 23:53:48 +0900 (Fri, 21 Feb 2014) New Revision: 45083 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45083 Log: merge revision(s) 44462,44477: [Backport #9314] * encoding.c (must_encindex, rb_enc_from_index, rb_obj_encoding): mask encoding index and ignore dummy flags. [ruby-core:59354] [Bug #9314] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/encoding.c branches/ruby_2_1/test/ruby/test_transcode.rb branches/ruby_2_1/version.h Index: ruby_2_1/encoding.c =================================================================== --- ruby_2_1/encoding.c (revision 45082) +++ ruby_2_1/encoding.c (revision 45083) @@ -156,7 +156,7 @@ must_encindex(int index) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/encoding.c#L156 rb_raise(rb_eEncodingError, "encoding index out of bound: %d", index); } - if (ENC_TO_ENCINDEX(enc) != index) { + if (ENC_TO_ENCINDEX(enc) != (int)(index & ENC_INDEX_MASK)) { rb_raise(rb_eEncodingError, "wrong encoding index %d for %s (expected %d)", index, rb_enc_name(enc), ENC_TO_ENCINDEX(enc)); } @@ -592,7 +592,7 @@ rb_enc_from_index(int index) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/encoding.c#L592 if (!enc_table.list) { rb_enc_init(); } - if (index < 0 || enc_table.count <= index) { + if (index < 0 || enc_table.count <= (index &= ENC_INDEX_MASK)) { return 0; } return enc_table.list[index].enc; @@ -933,7 +933,7 @@ rb_obj_encoding(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/encoding.c#L933 if (idx < 0) { rb_raise(rb_eTypeError, "unknown encoding"); } - return rb_enc_from_encoding_index(idx); + return rb_enc_from_encoding_index(idx & ENC_INDEX_MASK); } int Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 45082) +++ ruby_2_1/ChangeLog (revision 45083) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Fri Feb 21 23:51:38 2014 Nobuyoshi Nakada <nobu@r...> + + * encoding.c (must_encindex, rb_enc_from_index, rb_obj_encoding): mask + encoding index and ignore dummy flags. [ruby-core:59354] [Bug #9314] + Fri Feb 21 23:10:12 2014 Nobuyoshi Nakada <nobu@r...> * lib/mkmf.rb (RbConfig): expand RUBY_SO_NAME for extensions Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 45082) +++ ruby_2_1/version.h (revision 45083) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.1" #define RUBY_RELEASE_DATE "2014-02-21" -#define RUBY_PATCHLEVEL 46 +#define RUBY_PATCHLEVEL 47 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_1/test/ruby/test_transcode.rb =================================================================== --- ruby_2_1/test/ruby/test_transcode.rb (revision 45082) +++ ruby_2_1/test/ruby/test_transcode.rb (revision 45083) @@ -2080,4 +2080,15 @@ class TestTranscode < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_transcode.rb#L2080 assert_equal "\ufffd", str.encode(invalid: :replace), bug8995 end end + + def test_valid_dummy_encoding + bug9314 = '[ruby-core:59354] [Bug #9314]' + assert_separately(%W[- -- #{bug9314}], <<-'end;') + bug = ARGV.shift + result = assert_nothing_raised(TypeError, bug) {break "test".encode(Encoding::UTF_16)} + assert_equal("\xFE\xFF\x00t\x00e\x00s\x00t", result.b, bug) + result = assert_nothing_raised(TypeError, bug) {break "test".encode(Encoding::UTF_32)} + assert_equal("\x00\x00\xFE\xFF\x00\x00\x00t\x00\x00\x00e\x00\x00\x00s\x00\x00\x00t", result.b, bug) + end; + end end Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r44462,44477 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/