From 03621e5b3503775ab2378b879de7b738b0e64859 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 26 Apr 2016 14:35:24 +0000 Subject: Fix -e script encoding * ruby.c (process_options): convert -e script to the encoding given by a command line option on Windows. assume it is the expected encoding. [ruby-dev:49461] [Bug #11900] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 128de434d2..0273815200 100644 --- a/ruby.c +++ b/ruby.c @@ -1414,6 +1414,9 @@ process_options(int argc, char **argv, struct cmdline_options *opt) VALUE parser; const rb_iseq_t *iseq; rb_encoding *enc, *lenc; +#if UTF8_PATH + rb_encoding *uenc, *ienc = 0; +#endif const char *s; char fbuf[MAXPATHLEN]; int i = (int)proc_options(argc, argv, opt, 0); @@ -1525,6 +1528,9 @@ process_options(int argc, char **argv, struct cmdline_options *opt) enc = rb_enc_from_index(opt->intern.enc.index); rb_enc_set_default_internal(rb_enc_from_encoding(enc)); opt->intern.enc.index = -1; +#if UTF8_PATH + ienc = enc; +#endif } rb_enc_associate(opt->script_name, lenc); rb_obj_freeze(opt->script_name); @@ -1559,8 +1565,11 @@ process_options(int argc, char **argv, struct cmdline_options *opt) #undef SET_COMPILE_OPTION } #if UTF8_PATH - opt->script_name = str_conv_enc(opt->script_name, rb_utf8_encoding(), lenc); - opt->script = RSTRING_PTR(opt->script_name); + uenc = rb_utf8_encoding(); + 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); @@ -1578,7 +1587,15 @@ process_options(int argc, char **argv, struct cmdline_options *opt) } else { eenc = lenc; +#if UTF8_PATH + if (ienc) eenc = ienc; +#endif } +#if UTF8_PATH + if (eenc != uenc) { + opt->e_script = str_conv_enc(opt->e_script, uenc, eenc); + } +#endif rb_enc_associate(opt->e_script, eenc); if (!(opt->dump & ~DUMP_BIT(version_v))) { ruby_set_script_name(opt->script_name); -- cgit v1.2.3