File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Fri Feb 21 23:51:38 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+ * encoding.c (must_encindex, rb_enc_from_index, rb_obj_encoding): mask
4+ encoding index and ignore dummy flags. [ruby-core:59354] [Bug #9314]
5+
16Fri Feb 21 23:10:12 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
27
38 * lib/mkmf.rb (RbConfig): expand RUBY_SO_NAME for extensions
Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ must_encindex(int index)
156156 rb_raise (rb_eEncodingError , "encoding index out of bound: %d" ,
157157 index );
158158 }
159- if (ENC_TO_ENCINDEX (enc ) != index ) {
159+ if (ENC_TO_ENCINDEX (enc ) != ( int )( index & ENC_INDEX_MASK ) ) {
160160 rb_raise (rb_eEncodingError , "wrong encoding index %d for %s (expected %d)" ,
161161 index , rb_enc_name (enc ), ENC_TO_ENCINDEX (enc ));
162162 }
@@ -592,7 +592,7 @@ rb_enc_from_index(int index)
592592 if (!enc_table .list ) {
593593 rb_enc_init ();
594594 }
595- if (index < 0 || enc_table .count <= index ) {
595+ if (index < 0 || enc_table .count <= ( index &= ENC_INDEX_MASK ) ) {
596596 return 0 ;
597597 }
598598 return enc_table .list [index ].enc ;
@@ -933,7 +933,7 @@ rb_obj_encoding(VALUE obj)
933933 if (idx < 0 ) {
934934 rb_raise (rb_eTypeError , "unknown encoding" );
935935 }
936- return rb_enc_from_encoding_index (idx );
936+ return rb_enc_from_encoding_index (idx & ENC_INDEX_MASK );
937937}
938938
939939int
Original file line number Diff line number Diff line change @@ -2080,4 +2080,15 @@ def test_encode_with_invalid_chars
20802080 assert_equal "\ufffd " , str . encode ( invalid : :replace ) , bug8995
20812081 end
20822082 end
2083+
2084+ def test_valid_dummy_encoding
2085+ bug9314 = '[ruby-core:59354] [Bug #9314]'
2086+ assert_separately ( %W[ - -- #{ bug9314 } ] , <<-'end;' )
2087+ bug = ARGV.shift
2088+ result = assert_nothing_raised(TypeError, bug) {break "test".encode(Encoding::UTF_16)}
2089+ assert_equal("\xFE\xFF\x00t\x00e\x00s\x00t", result.b, bug)
2090+ result = assert_nothing_raised(TypeError, bug) {break "test".encode(Encoding::UTF_32)}
2091+ assert_equal("\x00\x00\xFE\xFF\x00\x00\x00t\x00\x00\x00e\x00\x00\x00s\x00\x00\x00t", result.b, bug)
2092+ end;
2093+ end
20832094end
Original file line number Diff line number Diff line change 11#define RUBY_VERSION "2.1.1"
22#define RUBY_RELEASE_DATE "2014-02-21"
3- #define RUBY_PATCHLEVEL 46
3+ #define RUBY_PATCHLEVEL 47
44
55#define RUBY_RELEASE_YEAR 2014
66#define RUBY_RELEASE_MONTH 2
You can’t perform that action at this time.
0 commit comments