1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

stringio: binmode sets encoding to ASCII-8BIT

This should match the behavior of IO#binmode as far
as treating content as ASCII-8BIT (binary).

* ext/stringio/stringio.c (strio_binmode): implement to set encoding
* test/stringio/test_stringio.rb (test_binmode): new test
  [ruby-core:72699] [Bug #11945]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2016-01-04 20:45:14 +00:00
parent 812c5798e2
commit dc59c76898
3 changed files with 27 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Tue Jan 5 05:06:51 2016 Eric Wong <e@80x24.org>
* ext/stringio/stringio.c (strio_binmode): implement to set encoding
* test/stringio/test_stringio.rb (test_binmode): new test
[ruby-core:72699] [Bug #11945]
Mon Jan 4 15:44:37 2016 Sho Hashimoto <sho-h@ruby-lang.org>
* variable.c (rb_mod_deprecate_constant): [DOC] added

View file

@ -493,7 +493,18 @@ strio_set_lineno(VALUE self, VALUE lineno)
return lineno;
}
#define strio_binmode strio_self
static VALUE
strio_binmode(VALUE self)
{
struct StringIO *ptr = StringIO(self);
rb_encoding *enc = rb_ascii8bit_encoding();
ptr->enc = enc;
if (WRITABLE(self)) {
rb_enc_associate(ptr->string, enc);
}
return self;
}
#define strio_fcntl strio_unimpl

View file

@ -665,4 +665,13 @@ class TestStringIO < Test::Unit::TestCase
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line(0){} }
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line("a",0){} }
end
def test_binmode
s = StringIO.new
s.set_encoding('utf-8')
assert_same s, s.binmode
bug_11945 = '[ruby-core:72699] [Bug #11945]'
assert_equal Encoding::ASCII_8BIT, s.external_encoding, bug_11945
end
end