[前][次][番号順一覧][スレッド一覧]

ruby-changes:64004

From: Lars <ko1@a...>
Date: Tue, 8 Dec 2020 01:49:05 +0900 (JST)
Subject: [ruby-changes:64004] 94b6933d1c (master): Set default for Encoding.default_external to UTF-8 on Windows (#2877)

https://git.ruby-lang.org/ruby.git/commit/?id=94b6933d1c

From 94b6933d1c6f4c8698319fbcac9dcecc9033b4b9 Mon Sep 17 00:00:00 2001
From: Lars Kanis <kanis@c...>
Date: Mon, 7 Dec 2020 17:48:37 +0100
Subject: Set default for Encoding.default_external to UTF-8 on Windows (#2877)

* Use UTF-8 as default for Encoding.default_external on Windows
* Document UTF-8 change on Windows to Encoding.default_external

fix https://bugs.ruby-lang.org/issues/16604

diff --git a/encoding.c b/encoding.c
index e1441ca..64748ce 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1684,7 +1684,9 @@ rb_enc_default_external(void) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1684
  * File data written to disk will be transcoded to the default external
  * encoding when written, if default_internal is not nil.
  *
- * The default external encoding is initialized by the locale or -E option.
+ * The default external encoding is initialized by the -E option.
+ * If -E isn't set, it is initialized to UTF-8 on Windows and the locale on
+ * other operating systems.
  */
 static VALUE
 get_default_external(VALUE klass)
diff --git a/ruby.c b/ruby.c
index 2ddea6b..c01d78e 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1819,6 +1819,9 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1819
     Init_ruby_description();
     Init_enc();
     lenc = rb_locale_encoding();
+#if UTF8_PATH
+    uenc = rb_utf8_encoding();
+#endif
     rb_enc_associate(rb_progname, lenc);
     rb_obj_freeze(rb_progname);
     parser = rb_parser_new();
@@ -1839,7 +1842,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1842
 	enc = rb_enc_from_index(opt->ext.enc.index);
     }
     else {
-	enc = lenc;
+	enc = IF_UTF8_PATH(uenc, lenc);
     }
     rb_enc_set_default_external(rb_enc_from_encoding(enc));
     if (opt->intern.enc.index >= 0) {
@@ -1944,7 +1947,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1947
 	enc = rb_enc_from_index(opt->ext.enc.index);
     }
     else {
-	enc = lenc;
+	enc = IF_UTF8_PATH(uenc, lenc);
     }
     rb_enc_set_default_external(rb_enc_from_encoding(enc));
     if (opt->intern.enc.index >= 0) {
diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb
index a060eab..7e71532 100644
--- a/spec/ruby/command_line/dash_upper_k_spec.rb
+++ b/spec/ruby/command_line/dash_upper_k_spec.rb
@@ -58,8 +58,8 @@ describe 'The -K command line option' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/command_line/dash_upper_k_spec.rb#L58
   end
 
   it "ignores unknown codes" do
-    locale = Encoding.find('locale')
+    external = Encoding.find('external')
     ruby_exe(@test_string, options: '-KZ').should ==
-      [Encoding::UTF_8.name, locale.name, nil].inspect
+      [Encoding::UTF_8.name, external.name, nil].inspect
   end
 end
diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb
index 8317878..853d9c9 100644
--- a/spec/ruby/library/stringio/binmode_spec.rb
+++ b/spec/ruby/library/stringio/binmode_spec.rb
@@ -9,7 +9,7 @@ describe "StringIO#binmode" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/binmode_spec.rb#L9
 
   it "changes external encoding to BINARY" do
     io = StringIO.new
-    io.external_encoding.should == Encoding.find('locale')
+    io.external_encoding.should == Encoding.find('external')
     io.binmode
     io.external_encoding.should == Encoding::BINARY
   end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]