commit
275f5a6209
|
@ -160,11 +160,13 @@ module Jekyll
|
|||
|
||||
questionable_path.insert(0, "/") if questionable_path.start_with?("~")
|
||||
clean_path = File.expand_path(questionable_path, "/")
|
||||
clean_path.sub!(%r!\A\w:/!, "/")
|
||||
|
||||
if clean_path.start_with?(base_directory.sub(%r!\A\w:/!, "/"))
|
||||
return clean_path if clean_path.eql?(base_directory)
|
||||
|
||||
if clean_path.start_with?(base_directory.sub(%r!\z!, "/"))
|
||||
clean_path
|
||||
else
|
||||
clean_path.sub!(%r!\A\w:/!, "/")
|
||||
File.join(base_directory, clean_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,4 +28,37 @@ class TestPathSanitization < JekyllUnitTest
|
|||
assert_equal source_dir("files", "hi.txt"),
|
||||
Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt")
|
||||
end
|
||||
|
||||
if Jekyll::Utils::Platforms.really_windows?
|
||||
context "on Windows with absolute path" do
|
||||
setup do
|
||||
@base_path = "D:/demo"
|
||||
@file_path = "D:/demo/_site"
|
||||
allow(Dir).to receive(:pwd).and_return("D:/")
|
||||
end
|
||||
|
||||
should "strip just the clean path drive name" do
|
||||
assert_equal "D:/demo/_site",
|
||||
Jekyll.sanitized_path(@base_path, @file_path)
|
||||
end
|
||||
end
|
||||
|
||||
context "on Windows with file path has matching prefix" do
|
||||
setup do
|
||||
@base_path = "D:/site"
|
||||
@file_path = "D:/sitemap.xml"
|
||||
allow(Dir).to receive(:pwd).and_return("D:/")
|
||||
end
|
||||
|
||||
should "not strip base path" do
|
||||
assert_equal "D:/site/sitemap.xml",
|
||||
Jekyll.sanitized_path(@base_path, @file_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "not strip base path if file path has matching prefix" do
|
||||
assert_equal "/site/sitemap.xml",
|
||||
Jekyll.sanitized_path("/site", "sitemap.xml")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue