Skip to content

Commit 031e048

Browse files
committed
Treat internal encoding as non-external Ruby option
1 parent 1ebb13f commit 031e048

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

react_on_rails/lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ end
8585
# outright ("invalid switch in RUBYOPT"), so it can never appear here.
8686
ARGUMENT_TAKING_SHORT_RUBYOPT_SWITCHES = %w[I r].freeze unless defined?(ARGUMENT_TAKING_SHORT_RUBYOPT_SWITCHES)
8787

88-
# True when RUBYOPT already pins a source encoding: a -E (including inside a short-option cluster
89-
# such as -wEUS-ASCII), or a --encoding/--external-encoding/--internal-encoding long option.
88+
# True when RUBYOPT already pins the external encoding: a -E (including inside a short-option cluster
89+
# such as -wEUS-ASCII), or a --encoding/--external-encoding long option.
9090
def rubyopt_pins_encoding?(rubyopt)
9191
rubyopt.split.any? { |token| rubyopt_token_pins_encoding?(token) }
9292
end
9393

9494
def rubyopt_token_pins_encoding?(token)
95-
return true if token.start_with?("--encoding", "--external-encoding", "--internal-encoding")
95+
return true if token.start_with?("--encoding", "--external-encoding")
9696
return false unless token.start_with?("-") && !token.start_with?("--") && token.length > 1
9797

9898
token[1..].each_char do |char|

react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5169,7 +5169,7 @@ class ActiveSupport::TestCase
51695169
expect(content).to include('[Encoding::US_ASCII, Encoding::ASCII_8BIT].include?(Encoding.find("locale"))')
51705170
expect(content).to include('"LANG" => "C.UTF-8"')
51715171
expect(content).to include('"LC_ALL" => "C.UTF-8"')
5172-
expect(content).to include('"RUBYOPT" => utf8_widened_rubyopt(ENV.fetch("RUBYOPT", ""))')
5172+
expect(content).to include('"RUBYOPT" => utf8_widened_rubyopt(subprocess_rubyopt(extra))')
51735173
expect(content).to include('"REACT_ON_RAILS_SKIP_VALIDATION" => "true"')
51745174
expect(content).to include('"RSC_BUNDLE_ONLY" => "true"')
51755175
expect(content).to include('"CLIENT_BUNDLE_ONLY" => nil')

react_on_rails/spec/react_on_rails/shakapacker_precompile_hook_shared_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ def bad_overrides.each_key
238238

239239
it "honors long-form encoding options" do
240240
["--encoding=US-ASCII", "--encoding US-ASCII",
241-
"--external-encoding=US-ASCII", "--external-encoding US-ASCII",
242-
"--internal-encoding=US-ASCII", "--internal-encoding US-ASCII"].each do |rubyopt|
241+
"--external-encoding=US-ASCII", "--external-encoding US-ASCII"].each do |rubyopt|
243242
with_locale_encoding(Encoding::US_ASCII) do
244243
with_env("RUBYOPT" => rubyopt) do
245244
expect(utf8_subprocess_env["RUBYOPT"]).to eq(rubyopt)
@@ -248,6 +247,16 @@ def bad_overrides.each_key
248247
end
249248
end
250249

250+
it "still pins UTF-8 when RUBYOPT only sets the internal encoding" do
251+
["--internal-encoding=US-ASCII", "--internal-encoding US-ASCII"].each do |rubyopt|
252+
with_locale_encoding(Encoding::US_ASCII) do
253+
with_env("RUBYOPT" => rubyopt) do
254+
expect(utf8_subprocess_env["RUBYOPT"]).to eq("-EUTF-8 #{rubyopt}")
255+
end
256+
end
257+
end
258+
end
259+
251260
it "still pins UTF-8 for argument-taking flags whose operand begins with E/K" do
252261
# -r/-I consume their operand, so -rEnglish / -rKconv / -IEpath are NOT encoding requests.
253262
# The pin must still be added (a regex that matched any E/K after - would wrongly skip these).

react_on_rails/spec/support/shakapacker_precompile_hook_shared.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def utf8_widened_rubyopt(rubyopt)
9191
# outright ("invalid switch in RUBYOPT"), so it can never appear here.
9292
ARGUMENT_TAKING_SHORT_RUBYOPT_SWITCHES = %w[I r].freeze unless defined?(ARGUMENT_TAKING_SHORT_RUBYOPT_SWITCHES)
9393

94-
# True when RUBYOPT already pins a source encoding: a -E (including inside a short-option cluster
95-
# such as -wEUS-ASCII), or a --encoding/--external-encoding/--internal-encoding long option.
94+
# True when RUBYOPT already pins the external encoding: a -E (including inside a short-option cluster
95+
# such as -wEUS-ASCII), or a --encoding/--external-encoding long option.
9696
def rubyopt_pins_encoding?(rubyopt)
9797
rubyopt.split.any? { |token| rubyopt_token_pins_encoding?(token) }
9898
end
9999

100100
def rubyopt_token_pins_encoding?(token)
101-
return true if token.start_with?("--encoding", "--external-encoding", "--internal-encoding")
101+
return true if token.start_with?("--encoding", "--external-encoding")
102102
return false unless token.start_with?("-") && !token.start_with?("--") && token.length > 1
103103

104104
token[1..].each_char do |char|

0 commit comments

Comments
 (0)