Strip extra slashes via `Jekyll.sanitized_path` (#7182)

Merge pull request 7182
This commit is contained in:
Ashwin Maroli 2018-09-24 22:57:44 +05:30 committed by jekyllbot
parent ce05f9cb15
commit 6eee8b7e06
2 changed files with 11 additions and 0 deletions

View File

@ -176,6 +176,10 @@ module Jekyll
return clean_path if clean_path.eql?(base_directory)
# remove any remaining extra leading slashes not stripped away by calling
# `File.expand_path` above.
clean_path.squeeze!("/")
if clean_path.start_with?(base_directory.sub(%r!\z!, "/"))
clean_path
else

View File

@ -31,6 +31,13 @@ class TestPathSanitization < JekyllUnitTest
Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt")
end
should "strip extra slashes in questionable path" do
subdir = "/files/"
file_path = "/hi.txt"
assert_equal source_dir("files", "hi.txt"),
Jekyll.sanitized_path(source_dir, "/#{subdir}/#{file_path}")
end
if Jekyll::Utils::Platforms.really_windows?
context "on Windows with absolute path" do
setup do