1

The support for mixing backslashes and forward slashes in the pathname module in the standard library seems to be broken on windows

require 'pathname'
base = Pathname.new("c:\\")
filepath = Pathname.new("c:/foo/bar/file.ext")
base.relative_path_from(filepath)

raises ArgumentError: different prefix: "c:\\" and "c:/foo/bar/file.ext"

Changing filepath to contain backslashes fixes the problem

filepath = Pathname.new("c:\\foo\\bar\\file.ext")
base.relative_path_from(filepath)

=> #<Pathname:../../..>

4

0 回答 0