summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-02-25 15:35:34 -0800
committerMatt Wrock <matt@mattwrock.com>2016-02-25 15:35:34 -0800
commit1cf4e878bf8609fafb76fa2097feb65595aacc4f (patch)
tree9ea4779b5b99c30483bca111b2b2cf783a1976ea
parentdbedc9c800dad338ecc1b50dd6770ab4e909a782 (diff)
parentb912d1075286261b0e9523cecff1997b59034b75 (diff)
downloadchef-1cf4e878bf8609fafb76fa2097feb65595aacc4f.tar.gz
Merge pull request #4626 from chef/umlaut
ensure paths maintain utf-8ness in non ascii encodings
-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)