Merge pull request #9998 from chrisroberts/f-plat-wsl-pathname

Always force string type conversion of path
This commit is contained in:
Chris Roberts 2018-07-18 16:37:07 -07:00 committed by GitHub
commit 2ba5c74e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -392,8 +392,9 @@ module Vagrant
# @param [String, Pathname] path Path to convert
# @return [String]
def wsl_to_windows_path(path)
path = path.to_s
if wsl? && wsl_windows_access? && !path.match(/^[a-zA-Z]:/)
path = File.expand_path(path.to_s)
path = File.expand_path(path)
if wsl_path?(path)
parts = path.split("/")
parts.delete_if(&:empty?)
@ -405,13 +406,13 @@ module Vagrant
end
path = [root_path, *parts].join("\\")
else
path = path.to_s.sub("/mnt/", "")
path = path.sub("/mnt/", "")
parts = path.split("/")
parts.first << ":"
path = parts.join("\\")
end
end
path.to_s
path
end
# Takes a windows path and formats it to the

View File

@ -353,6 +353,10 @@ describe Vagrant::Util::Platform do
it "should include rootfs when accessing non-home path" do
expect(subject.wsl_to_windows_path("/tmp/test")).to include("rootfs")
end
it "should properly handle Pathname" do
expect(subject.wsl_to_windows_path(Pathname.new("/tmp/test"))).to include("rootfs")
end
end
end
end