Skip to content

Commit 37095c4

Browse files
committed
merge revision(s) 44462,44477: [Backport ruby#9314]
* encoding.c (must_encindex, rb_enc_from_index, rb_obj_encoding): mask encoding index and ignore dummy flags. [ruby-core:59354] [Bug ruby#9314] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 2ae49e7 commit 37095c4

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Feb 21 23:51:38 2014 Nobuyoshi Nakada <[email protected]>
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+
16
Fri Feb 21 23:10:12 2014 Nobuyoshi Nakada <[email protected]>
27

38
* lib/mkmf.rb (RbConfig): expand RUBY_SO_NAME for extensions

encoding.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

939939
int

test/ruby/test_transcode.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
20832094
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

0 commit comments

Comments
 (0)