Merge pull request #8820 from chrisroberts/windows/exec-encoding

Update safe_exec argument encoding
This commit is contained in:
Chris Roberts 2017-07-26 15:38:30 -07:00 committed by GitHub
commit 4c0604e1af
1 changed files with 13 additions and 2 deletions

View File

@ -44,8 +44,19 @@ module Vagrant
# Re-generate strings to ensure common encoding # Re-generate strings to ensure common encoding
@@logger.debug("Converting command and arguments to common UTF-8 encoding for exec.") @@logger.debug("Converting command and arguments to common UTF-8 encoding for exec.")
@@logger.debug("Command: `#{command.inspect}` Args: `#{args.inspect}`") @@logger.debug("Command: `#{command.inspect}` Args: `#{args.inspect}`")
command = "#{command}".force_encoding("UTF-8") begin
args = args.map{|arg| "#{arg}".force_encoding("UTF-8") } command = "#{command}".encode("UTF-8")
rescue Encoding::UndefinedConversionError => e
@@logger.warn("Failed to convert command - #{e.class}: #{e} (`#{command}`)")
end
args = args.map do |arg|
begin
"#{arg}".encode("UTF-8")
rescue Encoding::UndefinedConversionError => e
@@logger.warn("Failed to convert command argument - #{e.class}: #{e} (`#{arg}`)")
arg
end
end
@@logger.debug("Converted - Command: `#{command.inspect}` Args: `#{args.inspect}`") @@logger.debug("Converted - Command: `#{command.inspect}` Args: `#{args.inspect}`")
end end
Kernel.exec(command, *args) Kernel.exec(command, *args)