diff options
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 2 | ||||
-rw-r--r-- | spec/data/client.d_00/02-strings.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 5 |
3 files changed, 8 insertions, 1 deletions
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 9b16b94910..adbdee1858 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -255,7 +255,7 @@ validation_client_name "#{@chef_config[:validation_client_name]}" content << "mkdir #{file_on_node}\n" else content << "cat > #{file_on_node} <<'EOP'\n" + - f.read + "\nEOP\n" + f.read.gsub("'", "'\\\\''") + "\nEOP\n" end end end diff --git a/spec/data/client.d_00/02-strings.rb b/spec/data/client.d_00/02-strings.rb new file mode 100644 index 0000000000..7d9a49268c --- /dev/null +++ b/spec/data/client.d_00/02-strings.rb @@ -0,0 +1,2 @@ +# 02-strings.rb +something '/foo/bar' diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 736ff9b099..c725526de7 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -516,6 +516,11 @@ describe Chef::Knife::Bootstrap do end context "a flat directory structure" do + it "escapes single-quotes" do + expect(rendered_template).to match("cat > /etc/chef/client.d/02-strings.rb <<'EOP'") + expect(rendered_template).to match("something '\\\\''/foo/bar'\\\\''") + end + it "creates a file 00-foo.rb" do expect(rendered_template).to match("cat > /etc/chef/client.d/00-foo.rb <<'EOP'") expect(rendered_template).to match("d6f9b976-289c-4149-baf7-81e6ffecf228") |