8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dac945b commit 2d17e3aCopy full SHA for 2d17e3a
ChangeLog
@@ -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
7
Thu Oct 16 22:06:03 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
8
9
* vm_eval.c (eval_string_with_cref): fix super from eval with
ext/stringio/stringio.c
@@ -1169,12 +1169,13 @@ strio_write(VALUE self, VALUE str)
1169
struct StringIO *ptr = writable(self);
1170
long len, olen;
1171
rb_encoding *enc, *enc2;
1172
+ rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
1173
1174
if (!RB_TYPE_P(str, T_STRING))
1175
str = rb_obj_as_string(str);
1176
enc = rb_enc_get(ptr->string);
1177
enc2 = rb_enc_get(str);
- if (enc != enc2 && enc != rb_ascii8bit_encoding()) {
1178
+ if (enc != enc2 && enc != ascii8bit) {
1179
str = rb_str_conv_enc(str, enc2, enc);
1180
}
1181
len = RSTRING_LEN(str);
@@ -1185,7 +1186,7 @@ strio_write(VALUE self, VALUE str)
1185
1186
ptr->pos = olen;
1187
1188
if (ptr->pos == olen) {
- if (enc2 == rb_ascii8bit_encoding()) {
1189
+ if (enc == ascii8bit || enc2 == ascii8bit) {
1190
rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc);
1191
OBJ_INFECT(ptr->string, str);
1192
test/stringio/test_stringio.rb
@@ -137,6 +137,18 @@ def test_write_encoding
137
assert_equal(Encoding::UTF_8, s.encoding, "honor the original encoding over ASCII-8BIT")
138
end
139
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
152
def test_mode_error
153
f = StringIO.new("", "r")
154
assert_raise(IOError) { f.write("foo") }
version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.4"
#define RUBY_RELEASE_DATE "2014-10-16"
-#define RUBY_PATCHLEVEL 258
+#define RUBY_PATCHLEVEL 259
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 10