From fc0707202a29d0c786a493a0075517fc4573ba3d Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 9 Nov 2018 10:19:35 -0800 Subject: [PATCH] FIXES #9870: Allow for windows path spaces with ssh utility Prior to this commit, if a windows path contained a space, the ssh utility could not properly find the private key path and the ssh command would fail. This commit adds some additional logic to the ssh utility to check if a path contains '%', and if so, use the IdentityFile argument. Otherwise it will default to passing in the private key file with '-i', which can support paths with spaces. --- lib/vagrant/util/ssh.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/util/ssh.rb b/lib/vagrant/util/ssh.rb index 6087f81a4..43d1dcfbf 100644 --- a/lib/vagrant/util/ssh.rb +++ b/lib/vagrant/util/ssh.rb @@ -150,11 +150,24 @@ module Vagrant if !plain_mode && options[:private_key_path] options[:private_key_path].each do |path| - # Use '-o' instead of '-i' because '-i' does not call - # percent_expand in misc.c, but '-o' does. when passing the path, - # replace '%' in the path with '%%' to escape the '%' - path = path.to_s.gsub('%', '%%') - command_options += ["-o", "IdentityFile=\"#{path}\""] + private_key_arr = [] + + if path.include?('%') + if path.include?(' ') && Platform.windows? + LOGGER.warn("Paths with spaces and % on windows is not supported and will fail to read the file") + end + # Use '-o' instead of '-i' because '-i' does not call + # percent_expand in misc.c, but '-o' does. when passing the path, + # replace '%' in the path with '%%' to escape the '%' + path = path.to_s.gsub('%', '%%') + private_key_arr = ["-o", "IdentityFile=\"#{path}\""] + else + # Pass private key file directly with '-i', which properly supports + # paths with spaces on Windows guests + private_key_arr = ["-i", path] + end + + command_options += private_key_arr end end