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:
commit
f37bb2a029
|
@ -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}")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue