summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chef-config/lib/chef-config/path_helper.rb2
-rw-r--r--lib/chef/mixin/path_sanity.rb2
-rw-r--r--spec/unit/mixin/path_sanity_spec.rb6
3 files changed, 8 insertions, 2 deletions
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb
index 10384974c7..42047b5e22 100644
--- a/chef-config/lib/chef-config/path_helper.rb
+++ b/chef-config/lib/chef-config/path_helper.rb
@@ -224,7 +224,7 @@ module ChefConfig
paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path }
# Filter out duplicate paths and paths that don't exist.
- valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path) }
+ valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path.force_encoding("utf-8")) }
valid_paths = valid_paths.uniq
# Join all optional path elements at the end.
diff --git a/lib/chef/mixin/path_sanity.rb b/lib/chef/mixin/path_sanity.rb
index 7078c585e0..6a8e017bcd 100644
--- a/lib/chef/mixin/path_sanity.rb
+++ b/lib/chef/mixin/path_sanity.rb
@@ -37,7 +37,7 @@ class Chef
env_path = env["PATH"].dup
env_path << path_separator unless env["PATH"].empty?
env_path << sane_path
- env["PATH"] = env_path
+ env["PATH"] = env_path.encode("utf-8", invalid: :replace, undef: :replace)
end
end
end
diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb
index e410f034d5..2c26e2fb79 100644
--- a/spec/unit/mixin/path_sanity_spec.rb
+++ b/spec/unit/mixin/path_sanity_spec.rb
@@ -56,6 +56,12 @@ describe Chef::Mixin::PathSanity do
expect(env["PATH"]).to eq("/usr/bin:/sbin:/bin:#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin")
end
+ it "creates path with utf-8 encoding" do
+ env = { "PATH" => "/usr/bin:/sbin:/bin:/b\x81t".force_encoding("ISO-8859-1") }
+ @sanity.enforce_path_sanity(env)
+ expect(env["PATH"].encoding.to_s).to eq("UTF-8")
+ end
+
it "adds the current executing Ruby's bindir and Gem bindir to the PATH" do
env = { "PATH" => "" }
@sanity.enforce_path_sanity(env)