Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out exclusively excluded entries sooner #7482

Merged
merged 5 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/jekyll/entry_filter.rb
Expand Up @@ -28,20 +28,30 @@ def relative_to_source(entry)
)
end

# rubocop:disable Metrics/CyclomaticComplexity
def filter(entries)
entries.reject do |e|
# Reject this entry if it is just a "dot" representation.
# e.g.: '.', '..', '_movies/.', 'music/..', etc
next true if e.end_with?(".")
# Reject this entry if it is a symlink.

# Check if the current entry is explicitly included and cache the result
included = included?(e)

# Reject current entry if it is excluded but not explicitly included as well.
next true if excluded?(e) && !included

# Reject current entry if it is a symlink.
next true if symlink?(e)
# Do not reject this entry if it is included.
next false if included?(e)

# Reject this entry if it is special, a backup file, or excluded.
special?(e) || backup?(e) || excluded?(e)
# Do not reject current entry if it is explicitly included.
next false if included

# Reject current entry if it is special or a backup file.
special?(e) || backup?(e)
end
end
# rubocop:enable Metrics/CyclomaticComplexity

def included?(entry)
glob_include?(site.include, entry) ||
Expand Down
10 changes: 10 additions & 0 deletions test/test_entry_filter.rb
Expand Up @@ -64,6 +64,16 @@ class TestEntryFilter < JekyllUnitTest
assert_equal files, @site.reader.filter_entries(files)
end

should "not exclude explicitly included entry" do
entries = %w(README TODO css .htaccess _movies/.)
excludes = %w(README TODO css)
includes = %w(README .htaccess)
@site.exclude = excludes
@site.include = includes
filtered_entries = EntryFilter.new(@site).filter(entries)
assert_equal %w(README .htaccess), filtered_entries
end

should "keep safe symlink entries when safe mode enabled" do
allow(File).to receive(:symlink?).with("symlink.js").and_return(true)
files = %w(symlink.js)
Expand Down