Ensure symlinks work as expected (and secured).

This commit is contained in:
Parker Moore 2016-04-21 16:32:52 -07:00
父節點 bac65ea8c5
當前提交 57ccbe08ea
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 193CDEBA72063C58
共有 3 個檔案被更改,包括 16 行新增1 行删除

查看文件

@ -34,10 +34,19 @@ module Jekyll
private
def path_for(folder)
path = Jekyll.sanitized_path root, "_#{folder}"
resolved_dir = realpath_for(folder)
return unless resolved_dir
path = Jekyll.sanitized_path(root, resolved_dir)
path if Dir.exists?(path)
end
def realpath_for(folder)
File.realpath(Jekyll.sanitized_path(root, "_#{folder}"))
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
nil
end
def gemspec
@gemspec ||= Gem::Specification.find_by_name(name)
rescue Gem::LoadError

1
test/fixtures/test-theme/_symlink vendored 符號連結
查看文件

@ -0,0 +1 @@
_layouts

查看文件

@ -52,6 +52,11 @@ class TestTheme < JekyllUnitTest
should "return nil for paths that don't exist" do
assert_equal nil, @theme.send(:path_for, "foo")
end
should "return the resolved path when a symlink & resolved path exists" do
expected = File.expand_path("./_layouts", @expected_root)
assert_equal expected, @theme.send(:path_for, :symlink)
end
end
should "retrieve the gemspec" do