[前][次][番号順一覧][スレッド一覧]

ruby-changes:72437

From: Nobuyoshi <ko1@a...>
Date: Wed, 6 Jul 2022 18:08:45 +0900 (JST)
Subject: [ruby-changes:72437] 5ef3c7ea2d (master): [Bug #18898] Fallback invalid external encoding to the default

https://git.ruby-lang.org/ruby.git/commit/?id=5ef3c7ea2d

From 5ef3c7ea2d1968c87f361b6615699b92cc6e5a9a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 6 Jul 2022 18:08:31 +0900
Subject: [Bug #18898] Fallback invalid external encoding to the default

---
 io.c                      |  4 +++-
 test/ruby/test_io_m17n.rb | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/io.c b/io.c
index 3915fa9a72..efe1ad944a 100644
--- a/io.c
+++ b/io.c
@@ -2914,6 +2914,8 @@ io_enc_str(VALUE str, rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L2914
     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) https://github.com/ruby/ruby/blob/trunk/io.c#L2927
         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 = "";
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 27b16a2a36..9c14087eba 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1142,8 +1142,18 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L1142
     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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]