diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 789d61ece..e1f2ea29c 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -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 diff --git a/test/unit/vagrant/util/platform_test.rb b/test/unit/vagrant/util/platform_test.rb index f43afd1d8..396148839 100644 --- a/test/unit/vagrant/util/platform_test.rb +++ b/test/unit/vagrant/util/platform_test.rb @@ -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