Use EntryFilter throughout & update tests
This commit is contained in:
parent
4aadfe9fd7
commit
9347e90a67
|
@ -94,7 +94,7 @@ module Jekyll
|
|||
Dir.chdir(directory) do
|
||||
entry_filter.filter(entries).reject do |f|
|
||||
path = collection_dir(f)
|
||||
File.directory?(path) || (File.symlink?(f) && site.safe)
|
||||
File.directory?(path) || entry_filter.symlink?(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -135,7 +135,7 @@ module Jekyll
|
|||
# Returns false if the directory doesn't exist or if it's a symlink
|
||||
# and we're in safe mode.
|
||||
def exists?
|
||||
File.directory?(directory) && !(File.symlink?(directory) && site.safe)
|
||||
File.directory?(directory) && !entry_filter.symlink?(directory)
|
||||
end
|
||||
|
||||
# The entry filter for this collection.
|
||||
|
|
|
@ -4,6 +4,7 @@ module Jekyll
|
|||
def initialize(site)
|
||||
@site = site
|
||||
@content = {}
|
||||
@entry_filter = EntryFilter.new(site)
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_drafts and create a new Draft
|
||||
|
@ -26,7 +27,7 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing
|
||||
def read_data_to(dir, data)
|
||||
return unless File.directory?(dir) && (!site.safe || !File.symlink?(dir))
|
||||
return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
|
||||
|
||||
entries = Dir.chdir(dir) do
|
||||
Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) }
|
||||
|
@ -34,7 +35,7 @@ module Jekyll
|
|||
|
||||
entries.each do |entry|
|
||||
path = @site.in_source_dir(dir, entry)
|
||||
next if File.symlink?(path) && site.safe
|
||||
next if @entry_filter.symlink?(path)
|
||||
|
||||
key = sanitize_filename(File.basename(entry, '.*'))
|
||||
if File.directory?(path)
|
||||
|
|
|
@ -179,13 +179,13 @@ class TestCollections < JekyllUnitTest
|
|||
@collection = @site.collections["methods"]
|
||||
end
|
||||
|
||||
should "not allow symlinks" do
|
||||
refute_includes @collection.filtered_entries, "um_hi.md"
|
||||
should "include the symlinked file as it resolves to inside site.source" do
|
||||
assert_includes @collection.filtered_entries, "um_hi.md"
|
||||
refute_includes @collection.filtered_entries, "/um_hi.md"
|
||||
end
|
||||
|
||||
should "not include the symlinked file in the list of docs" do
|
||||
refute_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md"
|
||||
should "include the symlinked file in the list of docs as it resolves to inside site.source" do
|
||||
assert_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -418,12 +418,12 @@ class TestSite < JekyllUnitTest
|
|||
assert_equal site.site_payload['site']['data']['products'], file_content
|
||||
end
|
||||
|
||||
should "not load symlink files in safe mode" do
|
||||
should "load the symlink files in safe mode, as they resolve to inside site.source" do
|
||||
site = Site.new(site_configuration('safe' => true))
|
||||
site.process
|
||||
|
||||
assert_nil site.data['products']
|
||||
assert_nil site.site_payload['site']['data']['products']
|
||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'products.yml'))
|
||||
assert_equal site.data['products'], file_content
|
||||
assert_equal site.site_payload['site']['data']['products'], file_content
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue