[前][次][番号順一覧][スレッド一覧]

ruby-changes:32383

From: nobu <ko1@a...>
Date: Mon, 30 Dec 2013 18:34:26 +0900 (JST)
Subject: [ruby-changes:32383] nobu:r44462 (trunk): encoding.c: mask dummy flags

nobu	2013-12-30 18:34:19 +0900 (Mon, 30 Dec 2013)

  New Revision: 44462

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44462

  Log:
    encoding.c: mask dummy flags
    
    * encoding.c (must_encindex, rb_enc_from_index, rb_obj_encoding): mask
      encoding index and ignore dummy flags.  [ruby-core:59354] [Bug #9314]

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/test/ruby/test_transcode.rb
Index: encoding.c
===================================================================
--- encoding.c	(revision 44461)
+++ encoding.c	(revision 44462)
@@ -156,7 +156,7 @@ must_encindex(int index) https://github.com/ruby/ruby/blob/trunk/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/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;
@@ -927,7 +927,7 @@ rb_obj_encoding(VALUE obj) https://github.com/ruby/ruby/blob/trunk/encoding.c#L927
     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: ChangeLog
===================================================================
--- ChangeLog	(revision 44461)
+++ ChangeLog	(revision 44462)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 30 18:34:18 2013  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]
+
 Mon Dec 30 16:11:52 2013  WATANABE Hirofumi  <eban@r...>
 
 	* tool/make-snapshot: needs CXXFLAGS.  [ruby-core:59393][Bug #9320]
Index: test/ruby/test_transcode.rb
===================================================================
--- test/ruby/test_transcode.rb	(revision 44461)
+++ test/ruby/test_transcode.rb	(revision 44462)
@@ -2080,4 +2080,15 @@ class TestTranscode < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/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) {break "test".encode(Encoding::UTF_16)}
+    assert_equal("\xFE\xFF\x00t\x00e\x00s\x00t", result.b)
+    result = assert_nothing_raised(TypeError) {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)
+    end;
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]