8000 stringio.c: ASCII-8BIT StringIO rejects no encodings · github/ruby@741436c · GitHub
[go: up one dir, main page]

Skip to content

Commit 741436c

Browse files
nobudbussink
authored andcommitted
stringio.c: ASCII-8BIT StringIO rejects no encodings
* 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/trunk@47716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog
1 parent da7ec40 commit 741436c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Fri Sep 26 12:52:36 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
Wed Sep 24 02:30:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
28

39
* parse.y (parse_ident): just after a label, new expression should

ext/stringio/stringio.c

Lines changed: 3 additions & 2 deletions
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

Lines changed: 12 additions & 0 deletions
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") }

0 commit comments

Comments
 (0)
0