mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Bug #18898] Fallback invalid external encoding to the default
This commit is contained in:
parent
53afacd036
commit
5ef3c7ea2d
Notes:
git
2022-07-06 18:08:53 +09:00
Merged: https://github.com/ruby/ruby/pull/6093 Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 13 additions and 1 deletions
4
io.c
4
io.c
|
@ -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)
|
||||
{
|
||||
|
@ -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 = "";
|
||||
|
|
|
@ -1142,8 +1142,18 @@ EOT
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue