Skip to content

Commit 184eeef

Browse files
authored
Merge pull request #656 from tvpartytonight/PA-5367_revert_ruby_utf8_default
(PA-5367) Revert ruby's 3.2 default to local encoding
2 parents 989b39e + a688efc commit 184eeef

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

configs/components/ruby-3.2.1.rb

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
pkg.apply_patch "#{base}/windows_nocodepage_utf8_fallback_r2.5.patch"
6262
pkg.apply_patch "#{base}/ruby-faster-load_32.patch"
6363
pkg.apply_patch "#{base}/revert-ruby-double-load-symlink.patch"
64+
pkg.apply_patch "#{base}/revert_ruby_utf8_default_encoding.patch"
6465
end
6566

6667
####################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
From 6f21c171d61a4e1b9dca020d6d3eae89bb0d2d90 Mon Sep 17 00:00:00 2001
2+
From: Tony Vu <[email protected]>
3+
Date: Thu, 6 Apr 2023 14:30:27 -0700
4+
Subject: [PATCH] Revert "Set default for Encoding.default_external to UTF-8 on
5+
Windows (#2877)"
6+
7+
This reverts commit 94b6933d1c6f4c8698319fbcac9dcecc9033b4b9.
8+
---
9+
encoding.c | 4 +---
10+
ruby.c | 4 ++--
11+
spec/ruby/command_line/dash_upper_k_spec.rb | 4 ++--
12+
spec/ruby/library/stringio/binmode_spec.rb | 2 +-
13+
4 files changed, 6 insertions(+), 8 deletions(-)
14+
15+
diff --git a/encoding.c b/encoding.c
16+
index 8bfab73177..29d3f5fdbb 100644
17+
--- a/encoding.c
18+
+++ b/encoding.c
19+
@@ -1587,9 +1587,7 @@ rb_enc_default_external(void)
20+
* File data written to disk will be transcoded to the default external
21+
* encoding when written, if default_internal is not nil.
22+
*
23+
- * The default external encoding is initialized by the -E option.
24+
- * If -E isn't set, it is initialized to UTF-8 on Windows and the locale on
25+
- * other operating systems.
26+
+ * The default external encoding is initialized by the locale or -E option.
27+
*/
28+
static VALUE
29+
get_default_external(VALUE klass)
30+
diff --git a/ruby.c b/ruby.c
31+
index f549e72fd0..1a1007dcce 100644
32+
--- a/ruby.c
33+
+++ b/ruby.c
34+
@@ -2026,7 +2026,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
35+
enc = rb_enc_from_index(opt->ext.enc.index);
36+
}
37+
else {
38+
- enc = IF_UTF8_PATH(uenc, lenc);
39+
+ enc = lenc;
40+
}
41+
rb_enc_set_default_external(rb_enc_from_encoding(enc));
42+
if (opt->intern.enc.index >= 0) {
43+
@@ -2146,7 +2146,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
44+
enc = rb_enc_from_index(opt->ext.enc.index);
45+
}
46+
else {
47+
- enc = IF_UTF8_PATH(uenc, lenc);
48+
+ enc = lenc;
49+
}
50+
rb_enc_set_default_external(rb_enc_from_encoding(enc));
51+
if (opt->intern.enc.index >= 0) {
52+
diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb
53+
index 7e71532295..a060eab793 100644
54+
--- a/spec/ruby/command_line/dash_upper_k_spec.rb
55+
+++ b/spec/ruby/command_line/dash_upper_k_spec.rb
56+
@@ -58,8 +58,8 @@
57+
end
58+
59+
it "ignores unknown codes" do
60+
- external = Encoding.find('external')
61+
+ locale = Encoding.find('locale')
62+
ruby_exe(@test_string, options: '-KZ').should ==
63+
- [Encoding::UTF_8.name, external.name, nil].inspect
64+
+ [Encoding::UTF_8.name, locale.name, nil].inspect
65+
end
66+
end
67+
diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb
68+
index 853d9c9bd6..83178787f3 100644
69+
--- a/spec/ruby/library/stringio/binmode_spec.rb
70+
+++ b/spec/ruby/library/stringio/binmode_spec.rb
71+
@@ -9,7 +9,7 @@
72+
73+
it "changes external encoding to BINARY" do
74+
io = StringIO.new
75+
- io.external_encoding.should == Encoding.find('external')
76+
+ io.external_encoding.should == Encoding.find('locale')
77+
io.binmode
78+
io.external_encoding.should == Encoding::BINARY
79+
end
80+
--
81+
2.37.1 (Apple Git-137.1)
82+

0 commit comments

Comments
 (0)