summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:43:39 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:43:39 +0000
commitce6fdd55bd0e892f75760bb50aec29dd063dfcea (patch)
treedf01a68eedaa0f2d42ed8b38b4e4a294dc9fbc53
parent0844dbdc372fe4f1d48fba8a28f2e5867ede1fec (diff)
merge revision(s) 54785: [Backport #11900]
* 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/branches/ruby_2_3@58029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ruby.c21
-rw-r--r--test/ruby/test_rubyoptions.rb28
-rw-r--r--version.h2
4 files changed, 54 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e0b959d32a..84c3f8b221 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Mar 20 06:35:08 2017 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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]
+
Mon Mar 20 05:47:49 2017 Koichi Sasada <ko1@atdot.net>
* test/ruby/test_exception.rb: fix thread issues.
diff --git a/ruby.c b/ruby.c
index c78093768a..7c32d4170d 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1368,6 +1368,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);
@@ -1478,6 +1481,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);
@@ -1512,8 +1518,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);
@@ -1537,7 +1546,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);
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index bb822eabcd..2dee9b5ddc 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -729,6 +729,34 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(["-e", "puts ARGV", "*.txt"], "", ougai)
end
end
+
+ def assert_e_script_encoding(str, args = [])
+ cmds = [
+ EnvUtil::LANG_ENVS.inject({}) {|h, k| h[k] = ENV[k]; h},
+ *args,
+ '-e', "s = '#{str}'",
+ '-e', 'puts s.encoding.name',
+ '-e', 'puts s.dump',
+ ]
+ assert_in_out_err(cmds, "", [str.encoding.name, str.dump], [],
+ "#{str.encoding}:#{str.dump} #{args.inspect}")
+ end
+
+ # tested codepages: 437 850 852 855 932 65001
+ # Since the codepage is shared all processes per conhost.exe, do
+ # not chcp, or parallel test may break.
+ def test_locale_codepage
+ locale = Encoding.find("locale")
+ list = %W"\u{c7} \u{452} \u{3066 3059 3068}"
+ list.each do |s|
+ assert_e_script_encoding(s, %w[-U])
+ end
+ list.each do |s|
+ s = s.encode(locale) rescue next
+ assert_e_script_encoding(s)
+ assert_e_script_encoding(s, %W[-E#{locale.name}])
+ end
+ end
when /cygwin/
def test_command_line_non_ascii
assert_separately([{"LC_ALL"=>"ja_JP.SJIS"}, "-", "\u{3042}".encode("SJIS")], <<-"end;")
diff --git a/version.h b/version.h
index dd3d52a037..4bd01f6133 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.3"
#define RUBY_RELEASE_DATE "2017-03-20"
-#define RUBY_PATCHLEVEL 250
+#define RUBY_PATCHLEVEL 251
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3