From 3e1c01ae463a8c9d8bbe9050251a2538ddb0292f Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 18 Dec 2015 07:54:33 +0000 Subject: stringio.c: separate encoding from buffer * ext/stringio/stringio.c (strio_set_encoding): add StringIO's own encoding and separate it from the buffer string to override the encoding of string when reading. [ruby-core:72189] [Bug #11827] note that setting the encoding of its buffer string may cause unpredictable behavior. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/stringio/test_stringio.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/stringio') diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 7b99d62f51..9a041c2148 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -148,6 +148,13 @@ class TestStringIO < Test::Unit::TestCase f.write(s) } assert_equal(Encoding::ASCII_8BIT, f.string.encoding, bug10285) + + bug11827 = '[ruby-core:72189] [Bug #11827]' + f = StringIO.new("foo\x83".freeze) + assert_nothing_raised(RuntimeError, bug11827) { + f.set_encoding(Encoding::ASCII_8BIT) + } + assert_equal("foo\x83".b, f.gets) end def test_mode_error -- cgit v1.2.3