Merge pull request #9506 from chrisroberts/f-path-invalid-input

Suppress errors from invalid path encoding and carry on with best effort
This commit is contained in:
Chris Roberts 2018-04-04 16:14:43 -07:00 committed by GitHub
commit f37bb2a029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 1 deletions

View File

@ -68,6 +68,7 @@ require 'openssl'
# Always make the version available
require 'vagrant/version'
global_logger = Log4r::Logger.new("vagrant::global")
Vagrant.global_logger = global_logger
global_logger.info("Vagrant version: #{Vagrant::VERSION}")
global_logger.info("Ruby version: #{RUBY_VERSION}")
global_logger.info("RubyGems version: #{Gem::VERSION}")

View File

@ -147,4 +147,23 @@ module Vagrant
end
end
end
# Set the global logger
#
# @param log Logger
# @return [Logger]
def self.global_logger=(log)
@_global_logger = log
end
# Get the global logger instance
#
# @return [Logger]
def self.global_logger
if @_global_logger.nil?
require "log4r"
@_global_logger = Log4r::Logger.new("vagrant::global")
end
@_global_logger
end
end

View File

@ -223,7 +223,15 @@ module Vagrant
# Traverse each part and join it into the resulting path
original.each do |single|
Dir.entries(path).each do |entry|
if entry.downcase == single.encode('filesystem').downcase
begin
single = single.encode("filesystem").to_s
rescue ArgumentError => err
Vagrant.global_logger.warn("path encoding failed - part=#{single} err=#{err.class} msg=#{err}")
# NOTE: Depending on the Windows environment the above
# encode will generate an "input string invalid" when
# attempting to encode. If that happens, continue on
end
if entry.downcase == single.downcase
path = path.join(entry)
end
end

View File

@ -162,4 +162,18 @@ describe Vagrant do
end
end
end
describe "#global_logger" do
after{ subject.global_logger = nil }
it "should return a logger when none have been provided" do
expect(subject.global_logger).not_to be_nil
end
it "should return previously set logger" do
logger = double("logger")
expect(subject.global_logger = logger).to eq(logger)
expect(subject.global_logger).to eq(logger)
end
end
end

View File

@ -133,6 +133,15 @@ describe Vagrant::Util::Platform do
it "fixes drive letters on Windows", :windows do
expect(described_class.fs_real_path("c:/foo").to_s).to eql("C:/foo")
end
it "gracefully handles invalid input string errors" do
bad_string = double("bad_string")
allow(bad_string).to receive(:to_s).and_raise(ArgumentError)
allow_any_instance_of(String).to receive(:encode).with("filesystem").and_return(bad_string)
allow(subject).to receive(:fs_case_sensitive?).and_return(false)
expect(described_class.fs_real_path("/dev/null").to_s).to eql("/dev/null")
end
end
describe "#windows_unc_path" do