summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-03-12 13:55:20 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-03-15 18:43:01 +0900
commite257c08f2ec27e2d66cdfa7e2415deb492522e22 (patch)
tree81fd971c2851d40248d0f1229661eda210b2c36e /ext
parentd79890cbfaa32444e3bab60835d7f09abf3d9469 (diff)
[ruby/stringio] StringIO#initialize default to the source string encoding
[Bug #16497] https://github.com/ruby/stringio/commit/4958a5ccab
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index c8057ee..b31e801 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -363,7 +363,12 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
rb_str_resize(string, 0);
}
ptr->string = string;
- ptr->enc = convconfig.enc;
+ if (argc == 1) {
+ ptr->enc = rb_enc_get(string);
+ }
+ else {
+ ptr->enc = convconfig.enc;
+ }
ptr->pos = 0;
ptr->lineno = 0;
if (ptr->flags & FMODE_SETENC_BY_BOM) set_encoding_by_bom(ptr);
@@ -1759,9 +1764,6 @@ strio_set_encoding_by_bom(VALUE self)
{
struct StringIO *ptr = StringIO(self);
- if (ptr->enc) {
- rb_raise(rb_eArgError, "encoding conversion is set");
- }
if (!set_encoding_by_bom(ptr)) return Qnil;
return rb_enc_from_encoding(ptr->enc);
}