Default stdin script encoding to UTF-8 on Windows

A script read from stdin used the locale encoding, so on a non-UTF-8
console such as CP932 its source encoding differed from a script read
from a file, which already defaults to UTF-8. Match both the Prism and
legacy paths to magic_comment_spec.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hiroshi SHIBATAandClaude Opus 4.8 committed 2026-06-29 08:09:51 +09:00
1 parent d5c649dc36
commit 4f84a740ee
1 file changed
+2 -2
Notes: git 2026-06-28 23:10:27 +00:00
+2 -2
View File
@@ -2227,7 +2227,7 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
const bool read_stdin = (strcmp(opt->script, "-") == 0);
if (read_stdin) {
pm_options_encoding_set(options, rb_enc_name(rb_locale_encoding()));
pm_options_encoding_set(options, rb_enc_name(IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding())));
}
if (opt->src.enc.name != 0) {
pm_options_encoding_set(options, StringValueCStr(opt->src.enc.name));
@@ -2844,7 +2844,7 @@ load_file_internal(VALUE argp_v)
enc = rb_enc_from_index(opt->src.enc.index);
}
else if (f == rb_stdin) {
enc = rb_locale_encoding();
enc = IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding());
}
else {
enc = rb_utf8_encoding();