Skip to content

Commit

Permalink
[Bug #18898] Fallback invalid external encoding to the default
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jul 6, 2022
1 parent 53afacd commit 5ef3c7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion io.c
Expand Up @@ -2914,6 +2914,8 @@ io_enc_str(VALUE str, rb_io_t *fptr)
return str;
}

static rb_encoding *io_read_encoding(rb_io_t *fptr);

static void
make_readconv(rb_io_t *fptr, int size)
{
Expand All @@ -2925,7 +2927,7 @@ make_readconv(rb_io_t *fptr, int size)
ecopts = fptr->encs.ecopts;
if (fptr->encs.enc2) {
sname = rb_enc_name(fptr->encs.enc2);
dname = rb_enc_name(fptr->encs.enc);
dname = rb_enc_name(io_read_encoding(fptr));
}
else {
sname = dname = "";
Expand Down
10 changes: 10 additions & 0 deletions test/ruby/test_io_m17n.rb
Expand Up @@ -1142,8 +1142,18 @@ def test_set_encoding_unsupported
IO.pipe do |r, w|
assert_nothing_raised(bug5567) do
assert_warning(/Unsupported/, bug5567) {r.set_encoding("fffffffffffxx")}
w.puts("foo")
assert_equal("foo\n", r.gets)
assert_warning(/Unsupported/, bug5567) {r.set_encoding("fffffffffffxx", "us-ascii")}
w.puts("bar")
assert_equal("bar\n", r.gets)
assert_warning(/Unsupported/, bug5567) {r.set_encoding("us-ascii", "fffffffffffxx")}
w.puts("zot")
begin
assert_equal("zot\n", r.gets)
rescue Encoding::ConverterNotFoundError => e
assert_match(/\((\S+) to \1\)/, e.message)
end
end
end
end
Expand Down

0 comments on commit 5ef3c7e

Please sign in to comment.