Skip to content

Commit

Permalink
Filter out exclusively excluded entries sooner (#7482)
Browse files Browse the repository at this point in the history
Merge pull request 7482
  • Loading branch information
ashmaroli committed May 20, 2020
1 parent bc3b92c commit 696e8e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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

0 comments on commit 696e8e4

Please sign in to comment.