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

ruby-changes:69997

From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Dec 2021 18:54:42 +0900 (JST)
Subject: [ruby-changes:69997] 37cd35aea8 (master): [win32] Transcode input from console [Bug #18353]

https://git.ruby-lang.org/ruby.git/commit/?id=37cd35aea8

From 37cd35aea8afa35476640e454eaf2c53150dc014 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 1 Dec 2021 15:05:16 +0900
Subject: [win32] Transcode input from console [Bug #18353]

On Windows, as the input from console is encoded in the active
code page, convert the input to the internal encoding.
---
 io.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/io.c b/io.c
index 366225089c0..b2ca5a69e37 100644
--- a/io.c
+++ b/io.c
@@ -12224,6 +12224,18 @@ rb_stdio_set_default_encoding(void) https://github.com/ruby/ruby/blob/trunk/io.c#L12224
 {
     VALUE val = Qnil;
 
+#ifdef _WIN32
+    if (isatty(fileno(stdin))) {
+        rb_encoding *external = rb_locale_encoding();
+        rb_encoding *internal = rb_default_internal_encoding();
+        if (!internal) internal = rb_default_external_encoding();
+        io_encoding_set(RFILE(rb_stdin)->fptr,
+                        rb_enc_from_encoding(external),
+                        rb_enc_from_encoding(internal),
+                        Qnil);
+    }
+    else
+#endif
     rb_io_set_encoding(1, &val, rb_stdin);
     rb_io_set_encoding(1, &val, rb_stdout);
     rb_io_set_encoding(1, &val, rb_stderr);
-- 
cgit v1.2.1


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

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