summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-02-24 20:27:56 -0800
committerMatt Wrock <matt@mattwrock.com>2016-02-24 20:27:56 -0800
commitb912d1075286261b0e9523cecff1997b59034b75 (patch)
tree1aea8c311c4a800e646f1ab0841e828b4812d1b0
parent1967e8c24ff5990f5352cec4ae84691b1643b2e1 (diff)
downloadchef-umlaut.tar.gz
ensure paths maintain utf-8ness in non ascii encodingsumlaut
-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)