diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-12-01 15:05:16 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-12-01 18:54:26 +0900 |
commit | 37cd35aea8afa35476640e454eaf2c53150dc014 (patch) | |
tree | fd59830c1c11ac79cedf6fe55589c22199a145e7 /io.c | |
parent | 0b53a8895f143ecc3d97844f5eec685dbd709d85 (diff) |
[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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5196
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -12224,6 +12224,18 @@ rb_stdio_set_default_encoding(void) { 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); |