diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-07-18 23:52:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-07-20 14:59:19 +0900 |
commit | 6ff9604f85bf5ffcb6dbfd9ff99ab420c9a5f415 (patch) | |
tree | f78d51354355cdf1bfe683e8451fc2bc1864645c /ext/stringio | |
parent | 840115bf46476dc2b3c175f7716b4d6000906f40 (diff) |
[ruby/stringio] Raise an error if encoding conversion not succeeded
As `rb_str_conv_enc()` returns the argument string object itself
unchanged when any conversion failed, check the incompatibility in
that case.
Fixes https://github.com/ruby/stringio/issues/13
https://github.com/ruby/stringio/commit/ede6bdcc71
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3334
Diffstat (limited to 'ext/stringio')
-rw-r--r-- | ext/stringio/stringio.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index b32a391b98..61a6b9a47c 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1435,7 +1435,12 @@ strio_write(VALUE self, VALUE str) enc = get_enc(ptr); enc2 = rb_enc_get(str); if (enc != enc2 && enc != ascii8bit) { - str = rb_str_conv_enc(str, enc2, enc); + VALUE converted = rb_str_conv_enc(str, enc2, enc); + if (converted == str && enc2 != ascii8bit) { /* conversion failed */ + rb_enc_check(rb_enc_from_encoding(enc), str); + UNREACHABLE; + } + str = converted; } len = RSTRING_LEN(str); if (len == 0) return 0; |