Skip to content

Commit

Permalink
ruby.c: script name in UTF-8
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jun 8, 2017
1 parent aac0b43 commit 238a624
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 238a624

Please sign in to comment.