From d9b9423ba8f7cb178992e7087f71f3f163685eba Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 17 May 2017 04:47:05 +0000 Subject: ruby.c: encode script name * ruby.c (process_options): encode script name to locale encoding instead of associate, if UTF-8 path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 3f89bb4ae6..5fb007334f 100644 --- a/ruby.c +++ b/ruby.c @@ -423,6 +423,8 @@ str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to) ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE, Qnil); } +#else +# define str_conv_enc(str, from, to) (str) #endif void ruby_init_loadpath_safe(int safe_level); @@ -1564,9 +1566,15 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) ienc = enc; #endif } - rb_enc_associate(opt->script_name, lenc); + if (IF_UTF8_PATH((uenc = rb_utf8_encoding()) != lenc, 0)) { + opt->script_name = str_conv_enc(opt->script_name, uenc, lenc); + opt->script = RSTRING_PTR(opt->script_name); + } + else { + rb_enc_associate(opt->script_name, lenc); + } rb_obj_freeze(opt->script_name); - if (IF_UTF8_PATH((uenc = rb_utf8_encoding()) != lenc, 1)) { + if (IF_UTF8_PATH(uenc != lenc, 1)) { long i; VALUE load_path = GET_VM()->load_path; const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK; @@ -1602,12 +1610,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_funcallv(rb_cISeq, rb_intern_const("compile_option="), 1, &option); #undef SET_COMPILE_OPTION } -#if UTF8_PATH - if (uenc != lenc) { - opt->script_name = str_conv_enc(opt->script_name, uenc, lenc); - opt->script = RSTRING_PTR(opt->script_name); - } -#endif ruby_set_argv(argc, argv); process_sflag(&opt->sflag); -- cgit v1.2.3