From 16dd06827973137241aea2f4b13d0e6b4c5f11e8 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 8 Jun 2017 02:07:42 +0000 Subject: ruby.c: script name in UTF-8 * ruby.c (process_options): keep script name in UTF-8 if UTF8_PATH to get rid of loss by conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 273fd4d1c4..94aaef96f9 100644 --- a/ruby.c +++ b/ruby.c @@ -1446,6 +1446,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) { NODE *tree = 0; VALUE parser; + VALUE script_name; const rb_iseq_t *iseq; rb_encoding *enc, *lenc; #if UTF8_PATH @@ -1570,13 +1571,15 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) ienc = enc; #endif } - if (IF_UTF8_PATH((uenc = rb_utf8_encoding()) != lenc, 0)) { + script_name = opt->script_name; + rb_enc_associate(opt->script_name, + IF_UTF8_PATH(uenc = rb_utf8_encoding(), lenc)); +#if UTF8_PATH + if (uenc != lenc) { 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); - } +#endif rb_obj_freeze(opt->script_name); if (IF_UTF8_PATH(uenc != lenc, 1)) { long i; @@ -1654,7 +1657,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) VALUE f; base_block = toplevel_context(toplevel_binding); rb_parser_set_context(parser, base_block, TRUE); - f = open_load_file(opt->script_name, &opt->xflag); + f = open_load_file(script_name, &opt->xflag); tree = load_file(parser, opt->script_name, f, 1, opt); } ruby_set_script_name(opt->script_name); @@ -1712,7 +1715,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) { VALUE path = Qnil; if (!opt->e_script && strcmp(opt->script, "-")) { - path = rb_realpath_internal(Qnil, opt->script_name, 1); + path = rb_realpath_internal(Qnil, script_name, 1); } base_block = toplevel_context(toplevel_binding); iseq = rb_iseq_new_main(tree, opt->script_name, path, vm_block_iseq(base_block)); -- cgit v1.2.3