diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-21 14:53:48 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-21 14:53:48 +0000 |
commit | b376132317cd2ad99647f41fc6ab03df6b7f8a84 (patch) | |
tree | 60942060a5b73280aaa94abaf56a3d655ce3b2ff | |
parent | 562f916fbdeb163c57992a9131409d938a5061fe (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | encoding.c | 6 | ||||
-rw-r--r-- | test/ruby/test_transcode.rb | 11 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 20 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Fri Feb 21 23:51:38 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * lib/mkmf.rb (RbConfig): expand RUBY_SO_NAME for extensions diff --git a/encoding.c b/encoding.c index 9bfda11f38..f102524379 100644 --- a/encoding.c +++ b/encoding.c @@ -156,7 +156,7 @@ must_encindex(int index) 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) 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) 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 diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 25c9d24663..5f3f51a676 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -2080,4 +2080,15 @@ class TestTranscode < Test::Unit::TestCase 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 @@ -1,6 +1,6 @@ #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 |