summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/stringio/stringio.c13
-rw-r--r--test/stringio/test_stringio.rb9
3 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 56af5bf414..9a9c7e32d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 23c4356f97..bd83ea207b 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 77a98726d8..e443fa6c26 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -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