diff options
author | Matt Wrock <matt@mattwrock.com> | 2016-10-14 06:19:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-14 06:19:28 -0700 |
commit | 86221072fef29ac0b5fd749d826508bacc41e091 (patch) | |
tree | 0e122b9c3735a792afc4ab88316aee61c91b6e50 | |
parent | 64e64ed67f888400abec358f955404e6845eee5e (diff) | |
parent | b2ae81e770255f935d0c75b3e0d7db1665609fd8 (diff) | |
download | chef-86221072fef29ac0b5fd749d826508bacc41e091.tar.gz |
Merge pull request #5430 from MsysTechnologiesllc/nim/double_quotes_issue
Fixed double quotes issue in powershell_out
-rw-r--r-- | lib/chef/mixin/powershell_out.rb | 2 | ||||
-rw-r--r-- | spec/unit/mixin/powershell_out_spec.rb | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/chef/mixin/powershell_out.rb b/lib/chef/mixin/powershell_out.rb index 74de85f86f..ab7cf00a72 100644 --- a/lib/chef/mixin/powershell_out.rb +++ b/lib/chef/mixin/powershell_out.rb @@ -91,7 +91,7 @@ class Chef "-InputFormat None", ] - "powershell.exe #{flags.join(' ')} -Command \"#{script}\"" + "powershell.exe #{flags.join(' ')} -Command \"#{script.gsub('"', '\"')}\"" end end end diff --git a/spec/unit/mixin/powershell_out_spec.rb b/spec/unit/mixin/powershell_out_spec.rb index 8e5f3588ce..4ecdcb8325 100644 --- a/spec/unit/mixin/powershell_out_spec.rb +++ b/spec/unit/mixin/powershell_out_spec.rb @@ -18,7 +18,7 @@ require "spec_helper" require "chef/mixin/powershell_out" -describe Chef::Mixin::PowershellOut do +describe Chef::Mixin::PowershellOut, :windows_only do let(:shell_out_class) { Class.new { include Chef::Mixin::PowershellOut } } subject(:object) { shell_out_class.new } let(:architecture) { "something" } @@ -44,6 +44,18 @@ describe Chef::Mixin::PowershellOut do ).and_return(ret) expect(object.powershell_out("Get-Process", timeout: 600)).to eql(ret) end + + context "when double quote is passed in the powershell command" do + it "passes if double quote is appended with single escape" do + result = object.powershell_out("Write-Verbose \"Some String\" -Verbose") + expect(result.stderr).to be == "" + expect(result.stdout).to be == "VERBOSE: Some String\n" + end + + it "suppresses error if double quote is passed with double escape characters" do + expect { object.powershell_out("Write-Verbose \\\"Some String\\\" -Verbose") }.not_to raise_error + end + end end describe "#powershell_out!" do @@ -66,5 +78,17 @@ describe Chef::Mixin::PowershellOut do expect(mixlib_shellout).to receive(:error!) expect(object.powershell_out!("Get-Process", timeout: 600)).to eql(mixlib_shellout) end + + context "when double quote is passed in the powershell command" do + it "passes if double quote is appended with single escape" do + result = object.powershell_out!("Write-Verbose \"Some String\" -Verbose") + expect(result.stderr).to be == "" + expect(result.stdout).to be == "VERBOSE: Some String\n" + end + + it "raises error if double quote is passed with double escape characters" do + expect { object.powershell_out!("Write-Verbose \\\"Some String\\\" -Verbose") }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) + end + end end end |