summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLars Kanis <kanis@comcard.de>2020-12-07 18:00:39 +0100
committerGitHub <noreply@github.com>2020-12-08 02:00:39 +0900
commitca76337a00244635faa331afd04f4b75161ce6fb (patch)
tree7fae6bdb4c21e81656b2c6399c26752f075bcce5 /spec
parent94b6933d1c6f4c8698319fbcac9dcecc9033b4b9 (diff)
Windows: Read ENV names and values as UTF-8 encoded Strings (#3818)
* Windows: Read ENV names and values as UTF-8 encoded Strings Implements issue #12650: fix https://bugs.ruby-lang.org/issues/12650 This also removes the special encoding for ENV['PATH'] and some complexity in the code that is unnecessary now. * Windows: Improve readablity of getenv() encoding getenv() did use the expected codepage as an implicit parameter of the macro. This is mis-leading since include/ruby/win32.h has a different definition. Using the "cp" variable explicit (like the other function calls) makes it more readable and consistent. * Windows: Change external C-API macros getenv() and execv() to use UTF-8 They used to process and return strings with locale encoding, but since all ruby-internal spawn and environment functions use UTF-8, it makes sense to change the C-API equally.
Notes
Notes: Merged-By: nurse <naruse@airemix.jp>
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/env/element_reference_spec.rb1
-rw-r--r--spec/ruby/core/env/fetch_spec.rb3
-rw-r--r--spec/ruby/core/env/shift_spec.rb5
-rw-r--r--spec/ruby/core/env/values_at_spec.rb3
4 files changed, 8 insertions, 4 deletions
diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb
index 1cd58ace54..22633e7a08 100644
--- a/spec/ruby/core/env/element_reference_spec.rb
+++ b/spec/ruby/core/env/element_reference_spec.rb
@@ -59,6 +59,7 @@ describe "ENV.[]" do
Encoding.default_internal = nil
locale = Encoding.find('locale')
+ locale = Encoding::UTF_8 if platform_is :windows
locale = Encoding::BINARY if locale == Encoding::US_ASCII
ENV[@variable] = "\xC3\xB8"
ENV[@variable].encoding.should == locale
diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb
index ef8f0a4ed3..f3af6f3dc2 100644
--- a/spec/ruby/core/env/fetch_spec.rb
+++ b/spec/ruby/core/env/fetch_spec.rb
@@ -56,7 +56,8 @@ describe "ENV.fetch" do
end
it "uses the locale encoding" do
+ encoding = platform_is(:windows) ? Encoding::UTF_8 : Encoding.find('locale')
ENV["foo"] = "bar"
- ENV.fetch("foo").encoding.should == Encoding.find('locale')
+ ENV.fetch("foo").encoding.should == encoding
end
end
diff --git a/spec/ruby/core/env/shift_spec.rb b/spec/ruby/core/env/shift_spec.rb
index 0fe08d4f6d..49d98c3729 100644
--- a/spec/ruby/core/env/shift_spec.rb
+++ b/spec/ruby/core/env/shift_spec.rb
@@ -42,9 +42,10 @@ describe "ENV.shift" do
it "uses the locale encoding if Encoding.default_internal is nil" do
Encoding.default_internal = nil
+ encoding = platform_is(:windows) ? Encoding::UTF_8 : Encoding.find('locale')
pair = ENV.shift
- pair.first.encoding.should equal(Encoding.find("locale"))
- pair.last.encoding.should equal(Encoding.find("locale"))
+ pair.first.encoding.should equal(encoding)
+ pair.last.encoding.should equal(encoding)
end
it "transcodes from the locale encoding to Encoding.default_internal if set" do
diff --git a/spec/ruby/core/env/values_at_spec.rb b/spec/ruby/core/env/values_at_spec.rb
index ee970e5f65..87c8c7f663 100644
--- a/spec/ruby/core/env/values_at_spec.rb
+++ b/spec/ruby/core/env/values_at_spec.rb
@@ -28,7 +28,8 @@ describe "ENV.values_at" do
end
it "uses the locale encoding" do
- ENV.values_at(ENV.keys.first).first.encoding.should == Encoding.find('locale')
+ encoding = platform_is(:windows) ? Encoding::UTF_8 : Encoding.find('locale')
+ ENV.values_at(ENV.keys.first).first.encoding.should == encoding
end
it "raises TypeError when a key is not coercible to String" do