Merge pull request #8495 from chrisroberts/fix/ssh-comm-empty-data

communicator/ssh: Do not pass empty data to registered blocks
This commit is contained in:
Chris Roberts 2017-04-18 14:01:24 -07:00 committed by GitHub
commit c085901c72
2 changed files with 38 additions and 2 deletions

View File

@ -519,7 +519,7 @@ module VagrantPlugins
end end
end end
if block_given? && marker_found if block_given? && marker_found && !data.empty?
yield :stdout, data yield :stdout, data
end end
end end
@ -540,7 +540,7 @@ module VagrantPlugins
end end
end end
if block_given? && marker_found if block_given? && marker_found && !data.empty?
yield :stderr, data yield :stderr, data
end end
end end

View File

@ -168,6 +168,24 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
end end
end end
context "with no command output" do
let(:command_stdout_data) do
"#{command_garbage_marker}"
end
it "does not send empty stdout data string" do
empty = true
expect(
communicator.execute("ls /") do |type, data|
if type == :stdout && data.empty?
empty = false
end
end
).to eq(0)
expect(empty).to be(true)
end
end
context "with garbage content prepended to command stderr output" do context "with garbage content prepended to command stderr output" do
let(:command_stderr_data) do let(:command_stderr_data) do
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n" "Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
@ -186,6 +204,24 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
end end
end end
context "with no command output on stderr" do
let(:command_stderr_data) do
"#{command_garbage_marker}"
end
it "does not send empty stderr data string" do
empty = true
expect(
communicator.execute("ls /") do |type, data|
if type == :stderr && data.empty?
empty = false
end
end
).to eq(0)
expect(empty).to be(true)
end
end
context "with pty enabled" do context "with pty enabled" do
before do before do
expect(ssh).to receive(:pty).and_return true expect(ssh).to receive(:pty).and_return true