summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNimishaS <nimisha.sharad@msystechnologies.com>2016-10-07 10:03:31 +0000
committerNimishaS <nimisha.sharad@msystechnologies.com>2016-10-07 10:11:35 +0000
commit8bbbe695e3a8042c2dc0514182fe60abf2bc102a (patch)
treebf1e87dd786dde1df1041efb838c3daa3aea811b
parent1a0c4c533be9e8a35a6fa8650e7a478f19d90ae6 (diff)
downloadchef-8bbbe695e3a8042c2dc0514182fe60abf2bc102a.tar.gz
Fixed double quotes issue in powershell_out
Signed-off-by: NimishaS <nimisha.sharad@msystechnologies.com>
-rw-r--r--lib/chef/mixin/powershell_out.rb2
-rw-r--r--spec/unit/mixin/powershell_out_spec.rb22
2 files changed, 23 insertions, 1 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..fb449e68ce 100644
--- a/spec/unit/mixin/powershell_out_spec.rb
+++ b/spec/unit/mixin/powershell_out_spec.rb
@@ -44,6 +44,17 @@ 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 == ""
+ 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 +77,16 @@ 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 == ""
+ 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