Skip to content

Commit 179f0ff

Browse files
committed
Windows: Change command line interface to UTF-8
- script name - include paths - script input from stdin
1 parent c224ca4 commit 179f0ff

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

ruby.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
21382138
const bool read_stdin = (strcmp(opt->script, "-") == 0);
21392139

21402140
if (read_stdin) {
2141-
pm_options_encoding_set(options, rb_enc_name(rb_locale_encoding()));
2141+
pm_options_encoding_set(options, rb_enc_name(IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding())));
21422142
}
21432143
if (opt->src.enc.name != 0) {
21442144
pm_options_encoding_set(options, StringValueCStr(opt->src.enc.name));
@@ -2408,14 +2408,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
24082408
#endif
24092409
}
24102410
rb_enc_associate(opt->script_name, IF_UTF8_PATH(uenc, lenc));
2411-
#if UTF8_PATH
2412-
if (uenc != lenc) {
2413-
opt->script_name = str_conv_enc(opt->script_name, uenc, lenc);
2414-
opt->script = RSTRING_PTR(opt->script_name);
2415-
}
2416-
#endif
24172411
rb_obj_freeze(opt->script_name);
2418-
if (IF_UTF8_PATH(uenc != lenc, 1)) {
2412+
{
24192413
long i;
24202414
VALUE load_path = vm->load_path;
24212415
const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
@@ -2425,13 +2419,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
24252419
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
24262420
VALUE path = RARRAY_AREF(load_path, i);
24272421
int mark = rb_attr_get(path, id_initial_load_path_mark) == path;
2428-
#if UTF8_PATH
2429-
VALUE newpath = rb_str_conv_enc(path, uenc, lenc);
2430-
if (newpath == path) continue;
2431-
path = newpath;
2432-
#else
2433-
if (!(path = copy_str(path, lenc, !mark))) continue;
2434-
#endif
2422+
if (!(path = copy_str(path, IF_UTF8_PATH(uenc, lenc), !mark))) continue;
24352423
if (mark) rb_ivar_set(path, id_initial_load_path_mark, path);
24362424
if (!modifiable) {
24372425
rb_ary_modify(load_path);
@@ -2559,11 +2547,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
25592547
VALUE path = Qnil;
25602548
if (!opt->e_script && strcmp(opt->script, "-")) {
25612549
path = rb_realpath_internal(Qnil, opt->script_name, 1);
2562-
#if UTF8_PATH
2563-
if (uenc != lenc) {
2564-
path = str_conv_enc(path, uenc, lenc);
2565-
}
2566-
#endif
25672550
if (!ENCODING_GET(path)) { /* ASCII-8BIT */
25682551
rb_enc_copy(path, opt->script_name);
25692552
}
@@ -2725,7 +2708,7 @@ load_file_internal(VALUE argp_v)
27252708
enc = rb_enc_from_index(opt->src.enc.index);
27262709
}
27272710
else if (f == rb_stdin) {
2728-
enc = rb_locale_encoding();
2711+
enc = IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding());
27292712
}
27302713
else {
27312714
enc = rb_utf8_encoding();

test/ruby/test_rubyoptions.rb

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,19 +1028,11 @@ def test_command_line_glob_nonascii
10281028

10291029
def test_command_line_progname_nonascii
10301030
bug10555 = '[ruby-dev:48752] [Bug #10555]'
1031-
name = expected = nil
1032-
unless (0x80..0x10000).any? {|c|
1033-
name = c.chr(Encoding::UTF_8)
1034-
expected = name.encode("locale") rescue nil
1035-
}
1036-
omit "can't make locale name"
1037-
end
1038-
name << ".rb"
1039-
expected << ".rb"
1031+
name = "\u{20ac}.rb"
10401032
with_tmpchdir do |dir|
10411033
open(name, "w") {|f| f.puts "puts File.basename($0)"}
1042-
assert_in_out_err([name], "", [expected], [],
1043-
bug10555, encoding: "locale")
1034+
assert_in_out_err([name], "", [name], [],
1035+
bug10555, encoding: "utf-8")
10441036
end
10451037
end
10461038

0 commit comments

Comments
 (0)