Skip to content

Commit 2d17e3a

Browse files
committed
merge revision(s) r47716: [Backport ruby#10285]
* ext/stringio/stringio.c (strio_write): ASCII-8BIT StringIO should be writable any encoding strings, without conversion. [ruby-core:65240] [Bug ruby#10285] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent dac945b commit 2d17e3a

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Thu Oct 16 22:10:11 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* ext/stringio/stringio.c (strio_write): ASCII-8BIT StringIO
4+
should be writable any encoding strings, without conversion.
5+
[ruby-core:65240] [Bug #10285]
6+
17
Thu Oct 16 22:06:03 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
28

39
* vm_eval.c (eval_string_with_cref): fix super from eval with

ext/stringio/stringio.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,13 @@ strio_write(VALUE self, VALUE str)
11691169
struct StringIO *ptr = writable(self);
11701170
long len, olen;
11711171
rb_encoding *enc, *enc2;
1172+
rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
11721173

11731174
if (!RB_TYPE_P(str, T_STRING))
11741175
str = rb_obj_as_string(str);
11751176
enc = rb_enc_get(ptr->string);
11761177
enc2 = rb_enc_get(str);
1177-
if (enc != enc2 && enc != rb_ascii8bit_encoding()) {
1178+
if (enc != enc2 && enc != ascii8bit) {
11781179
str = rb_str_conv_enc(str, enc2, enc);
11791180
}
11801181
len = RSTRING_LEN(str);
@@ -1185,7 +1186,7 @@ strio_write(VALUE self, VALUE str)
11851186
ptr->pos = olen;
11861187
}
11871188
if (ptr->pos == olen) {
1188-
if (enc2 == rb_ascii8bit_encoding()) {
1189+
if (enc == ascii8bit || enc2 == ascii8bit) {
11891190
rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc);
11901191
OBJ_INFECT(ptr->string, str);
11911192
}

test/stringio/test_stringio.rb

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ def test_write_encoding
137137
assert_equal(Encoding::UTF_8, s.encoding, "honor the original encoding over ASCII-8BIT")
138138
end
139139

140+
def test_set_encoding
141+
bug10285 = '[ruby-core:65240] [Bug #10285]'
142+
f = StringIO.new()
143+
f.set_encoding(Encoding::ASCII_8BIT)
144+
f.write("quz \x83 mat".b)
145+
s = "foo \x97 bar".force_encoding(Encoding::WINDOWS_1252)
146+
assert_nothing_raised(Encoding::CompatibilityError, bug10285) {
147+
f.write(s)
148+
}
149+
assert_equal(Encoding::ASCII_8BIT, f.string.encoding, bug10285)
150+
end
151+
140152
def test_mode_error
141153
f = StringIO.new("", "r")
142154
assert_raise(IOError) { f.write("foo") }

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.4"
22
#define RUBY_RELEASE_DATE "2014-10-16"
3-
#define RUBY_PATCHLEVEL 258
3+
#define RUBY_PATCHLEVEL 259
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 10

0 commit comments

Comments
 (0)