diff --git a/plugins/guests/darwin/cap/shell_expand_guest_path.rb b/plugins/guests/darwin/cap/shell_expand_guest_path.rb index 22c7bd11a..f4c892911 100644 --- a/plugins/guests/darwin/cap/shell_expand_guest_path.rb +++ b/plugins/guests/darwin/cap/shell_expand_guest_path.rb @@ -4,7 +4,8 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf \"#{path}\"") do |type, data| + path = path.gsub(/ /, '\ ') + machine.communicate.execute("printf #{path}") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb index 14ae7184d..aee7600fb 100644 --- a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,8 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf \"#{path}\"", + path = path.gsub(/ /, '\ ') + machine.communicate.execute("printf #{path}", shell: "sh") do |type, data| if type == :stdout real_path ||= "" diff --git a/plugins/guests/linux/cap/shell_expand_guest_path.rb b/plugins/guests/linux/cap/shell_expand_guest_path.rb index 653068a78..085866deb 100644 --- a/plugins/guests/linux/cap/shell_expand_guest_path.rb +++ b/plugins/guests/linux/cap/shell_expand_guest_path.rb @@ -4,7 +4,8 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("echo; printf \"#{path}\"") do |type, data| + path = path.gsub(/ /, '\ ') + machine.communicate.execute("echo; printf #{path}") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb index 007c5f944..52712d84f 100644 --- a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,8 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf \"#{path}\"") do |type, data| + path = path.gsub(/ /, '\ ') + machine.communicate.execute("printf #{path}") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb index 2a4f8b5ed..9defdff77 100644 --- a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb @@ -4,7 +4,8 @@ module VagrantPlugins class ShellExpandGuestPath def self.shell_expand_guest_path(machine, path) real_path = nil - machine.communicate.execute("printf \"#{path}\"") do |type, data| + path = path.gsub(/ /, '\ ') + machine.communicate.execute("printf #{path}") do |type, data| if type == :stdout real_path ||= "" real_path += data diff --git a/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb index fbbc45588..10fc01bf5 100644 --- a/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb +++ b/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb @@ -33,10 +33,11 @@ describe "VagrantPlugins::GuestDarwin::Cap::ShellExpandGuestPath" do it "returns a path with a space in it" do path = "/home/vagrant folder/folder" + path_with_spaces = "/home/vagrant\\ folder/folder" allow(machine.communicate).to receive(:execute). - with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + with(any_args).and_yield(:stdout, path_with_spaces) - expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + expect(machine.communicate).to receive(:execute).with("printf #{path_with_spaces}") cap.shell_expand_guest_path(machine, path) end end diff --git a/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb index 2f10f8663..334cdd40c 100644 --- a/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb +++ b/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb @@ -33,11 +33,12 @@ describe "VagrantPlugins::GuestFreeBSD::Cap::ShellExpandGuestPath" do it "returns a path with a space in it" do path = "/home/vagrant folder/folder" + path_with_spaces = "/home/vagrant\\ folder/folder" allow(machine.communicate).to receive(:execute). - with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + with(any_args).and_yield(:stdout, path_with_spaces) expect(machine.communicate).to receive(:execute) - .with("printf \"#{path}\"", {:shell=>"sh"}) + .with("printf #{path_with_spaces}", {:shell=>"sh"}) cap.shell_expand_guest_path(machine, path) end end diff --git a/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb index 0caf4ae1d..b4abb29f6 100644 --- a/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb +++ b/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb @@ -33,10 +33,11 @@ describe "VagrantPlugins::GuestLinux::Cap::ShellExpandGuestPath" do it "returns a path with a space in it" do path = "/home/vagrant folder/folder" + path_with_spaces = "/home/vagrant\\ folder/folder" allow(machine.communicate).to receive(:execute). - with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + with(any_args).and_yield(:stdout, path_with_spaces) - expect(machine.communicate).to receive(:execute).with("echo; printf \"#{path}\"") + expect(machine.communicate).to receive(:execute).with("echo; printf #{path_with_spaces}") cap.shell_expand_guest_path(machine, path) end end diff --git a/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb index 49e4e6305..9cd7ca6b6 100644 --- a/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb +++ b/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb @@ -33,10 +33,11 @@ describe "VagrantPlugins::GuestNetBSD::Cap::ShellExpandGuestPath" do it "returns a path with a space in it" do path = "/home/vagrant folder/folder" + path_with_spaces = "/home/vagrant\\ folder/folder" allow(machine.communicate).to receive(:execute). - with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + with(any_args).and_yield(:stdout, path_with_spaces) - expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + expect(machine.communicate).to receive(:execute).with("printf #{path_with_spaces}") cap.shell_expand_guest_path(machine, path) end end diff --git a/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb index 1cd787911..89d14dcca 100644 --- a/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb +++ b/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb @@ -33,10 +33,11 @@ describe "VagrantPlugins::GuestOpenBSD::Cap::ShellExpandGuestPath" do it "returns a path with a space in it" do path = "/home/vagrant folder/folder" + path_with_spaces = "/home/vagrant\\ folder/folder" allow(machine.communicate).to receive(:execute). - with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + with(any_args).and_yield(:stdout, path_with_spaces) - expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + expect(machine.communicate).to receive(:execute).with("printf #{path_with_spaces}") cap.shell_expand_guest_path(machine, path) end end