|
| 1 | +From fc347d3c3571264b7e35ebcac36762c084b01825 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Lars Kanis <lars@greiz-reinsdorf.de> |
| 3 | +Date: Wed, 2 Oct 2024 22:44:21 +0200 |
| 4 | +Subject: [PATCH] Windows: Change command line interface to UTF-8 |
| 5 | + |
| 6 | +- script name |
| 7 | +- include paths |
| 8 | +- script input from stdin |
| 9 | +--- |
| 10 | + ruby.c | 25 ++++--------------------- |
| 11 | + test/ruby/test_rubyoptions.rb | 14 +++----------- |
| 12 | + 2 files changed, 7 insertions(+), 32 deletions(-) |
| 13 | + |
| 14 | +diff --git a/ruby.c b/ruby.c |
| 15 | +index 61de5cdcbe..e79d4b69da 100644 |
| 16 | +--- a/ruby.c |
| 17 | ++++ b/ruby.c |
| 18 | +@@ -2168,7 +2168,7 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result) |
| 19 | + const bool read_stdin = (strcmp(opt->script, "-") == 0); |
| 20 | + |
| 21 | + if (read_stdin) { |
| 22 | +- pm_options_encoding_set(options, rb_enc_name(rb_locale_encoding())); |
| 23 | ++ pm_options_encoding_set(options, rb_enc_name(IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding()))); |
| 24 | + } |
| 25 | + if (opt->src.enc.name != 0) { |
| 26 | + pm_options_encoding_set(options, StringValueCStr(opt->src.enc.name)); |
| 27 | +@@ -2443,14 +2443,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) |
| 28 | + #endif |
| 29 | + } |
| 30 | + rb_enc_associate(opt->script_name, IF_UTF8_PATH(uenc, lenc)); |
| 31 | +-#if UTF8_PATH |
| 32 | +- if (uenc != lenc) { |
| 33 | +- opt->script_name = str_conv_enc(opt->script_name, uenc, lenc); |
| 34 | +- opt->script = RSTRING_PTR(opt->script_name); |
| 35 | +- } |
| 36 | +-#endif |
| 37 | + rb_obj_freeze(opt->script_name); |
| 38 | +- if (IF_UTF8_PATH(uenc != lenc, 1)) { |
| 39 | ++ { |
| 40 | + long i; |
| 41 | + VALUE load_path = vm->load_path; |
| 42 | + const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK; |
| 43 | +@@ -2460,13 +2454,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) |
| 44 | + for (i = 0; i < RARRAY_LEN(load_path); ++i) { |
| 45 | + VALUE path = RARRAY_AREF(load_path, i); |
| 46 | + int mark = rb_attr_get(path, id_initial_load_path_mark) == path; |
| 47 | +-#if UTF8_PATH |
| 48 | +- VALUE newpath = rb_str_conv_enc(path, uenc, lenc); |
| 49 | +- if (newpath == path) continue; |
| 50 | +- path = newpath; |
| 51 | +-#else |
| 52 | +- if (!(path = copy_str(path, lenc, !mark))) continue; |
| 53 | +-#endif |
| 54 | ++ if (!(path = copy_str(path, IF_UTF8_PATH(uenc, lenc), !mark))) continue; |
| 55 | + if (mark) rb_ivar_set(path, id_initial_load_path_mark, path); |
| 56 | + if (!modifiable) { |
| 57 | + rb_ary_modify(load_path); |
| 58 | +@@ -2594,11 +2582,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) |
| 59 | + VALUE path = Qnil; |
| 60 | + if (!opt->e_script && strcmp(opt->script, "-")) { |
| 61 | + path = rb_realpath_internal(Qnil, opt->script_name, 1); |
| 62 | +-#if UTF8_PATH |
| 63 | +- if (uenc != lenc) { |
| 64 | +- path = str_conv_enc(path, uenc, lenc); |
| 65 | +- } |
| 66 | +-#endif |
| 67 | + if (!ENCODING_GET(path)) { /* ASCII-8BIT */ |
| 68 | + rb_enc_copy(path, opt->script_name); |
| 69 | + } |
| 70 | +@@ -2760,7 +2743,7 @@ load_file_internal(VALUE argp_v) |
| 71 | + enc = rb_enc_from_index(opt->src.enc.index); |
| 72 | + } |
| 73 | + else if (f == rb_stdin) { |
| 74 | +- enc = rb_locale_encoding(); |
| 75 | ++ enc = IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding()); |
| 76 | + } |
| 77 | + else { |
| 78 | + enc = rb_utf8_encoding(); |
| 79 | +diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb |
| 80 | +index ac4b5870eb..fac0901fdf 100644 |
| 81 | +--- a/test/ruby/test_rubyoptions.rb |
| 82 | ++++ b/test/ruby/test_rubyoptions.rb |
| 83 | +@@ -1082,19 +1082,11 @@ def test_command_line_glob_nonascii |
| 84 | + |
| 85 | + def test_command_line_progname_nonascii |
| 86 | + bug10555 = '[ruby-dev:48752] [Bug #10555]' |
| 87 | +- name = expected = nil |
| 88 | +- unless (0x80..0x10000).any? {|c| |
| 89 | +- name = c.chr(Encoding::UTF_8) |
| 90 | +- expected = name.encode("locale") rescue nil |
| 91 | +- } |
| 92 | +- omit "can't make locale name" |
| 93 | +- end |
| 94 | +- name << ".rb" |
| 95 | +- expected << ".rb" |
| 96 | ++ name = "\u{20ac}.rb" |
| 97 | + with_tmpchdir do |dir| |
| 98 | + open(name, "w") {|f| f.puts "puts File.basename($0)"} |
| 99 | +- assert_in_out_err([name], "", [expected], [], |
| 100 | +- bug10555, encoding: "locale") |
| 101 | ++ assert_in_out_err([name], "", [name], [], |
| 102 | ++ bug10555, encoding: "utf-8") |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | +-- |
| 107 | +2.47.1.windows.1 |
| 108 | + |
0 commit comments