summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-16 16:38:45 -0700
committerGitHub <noreply@github.com>2016-09-16 16:38:45 -0700
commit8779797e6dc67f34eb9fb7bf8908e77d86a70e74 (patch)
treebadd83d046815aeae0f91ef72f92e4fae01d3810
parent6cfcd38f11217cf8e4a39ec1b530840242828522 (diff)
downloadchef-8779797e6dc67f34eb9fb7bf8908e77d86a70e74.tar.gz
add a test for non-utf8 chars in filenames in the file provider (#5335)
fix non-utf8 filename issues in the file provider (again)
-rw-r--r--kitchen-tests/cookbooks/base/recipes/default.rb4
-rw-r--r--kitchen-tests/cookbooks/base/recipes/tests.rb21
-rw-r--r--lib/chef/file_content_management/tempfile.rb5
-rw-r--r--lib/chef/resource/file.rb2
4 files changed, 29 insertions, 3 deletions
diff --git a/kitchen-tests/cookbooks/base/recipes/default.rb b/kitchen-tests/cookbooks/base/recipes/default.rb
index 2499dcb814..397d50c016 100644
--- a/kitchen-tests/cookbooks/base/recipes/default.rb
+++ b/kitchen-tests/cookbooks/base/recipes/default.rb
@@ -28,7 +28,7 @@ end
include_recipe "build-essential"
-include_recipe "#{cookbook_name}::packages"
+include_recipe "::packages"
include_recipe "ntp"
@@ -50,3 +50,5 @@ include_recipe "openssh"
include_recipe "nscd"
include_recipe "logrotate"
+
+include_recipe "::tests"
diff --git a/kitchen-tests/cookbooks/base/recipes/tests.rb b/kitchen-tests/cookbooks/base/recipes/tests.rb
new file mode 100644
index 0000000000..9d9d813865
--- /dev/null
+++ b/kitchen-tests/cookbooks/base/recipes/tests.rb
@@ -0,0 +1,21 @@
+#
+# Cookbook Name:: webapp
+# Recipe:: default
+#
+# Copyright (C) 2014
+#
+
+#
+# this file is for random tests to check specific chef-client internal functionality
+#
+
+file "/tmp/chef-test-ümlauts" do
+ content "testing UTF-8 char in the filename"
+end
+
+# this caught a regression in 12.14.70 before it was released when i
+# ran it in lamont-ci, so added the test here so everyone else other than
+# me gets coverage for this as well.
+file "/tmp/chef-test-\xFDmlaut" do
+ content "testing illegal UTF-8 char in the filename"
+end
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb
index eb9154c4b1..cf59a87996 100644
--- a/lib/chef/file_content_management/tempfile.rb
+++ b/lib/chef/file_content_management/tempfile.rb
@@ -73,7 +73,10 @@ class Chef
# this is similar to File.extname() but greedy about the extension (from the first dot, not the last dot)
def tempfile_extension
- File.basename(@new_resource.path)[/\..*/] || ""
+ # complexity here is due to supporting mangling non-UTF8 strings (e.g. latin-1 filenames with characters that are illegal in UTF-8)
+ b = File.basename(@new_resource.path)
+ i = b.index(".")
+ i.nil? ? "" : b[i..-1]
end
# Returns the possible directories for the tempfile to be created in.
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 7088e7613e..207de63778 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -81,7 +81,7 @@ class Chef
end
def special_docker_files?(file)
- %w{/etc/hosts /etc/hostname /etc/resolv.conf}.include?(Pathname(file).cleanpath.to_path)
+ %w{/etc/hosts /etc/hostname /etc/resolv.conf}.include?(Pathname(file.scrub).cleanpath.to_path)
end
end
end