diff --git a/lib/jekyll/entry_filter.rb b/lib/jekyll/entry_filter.rb index 49404a769be..787625e210a 100644 --- a/lib/jekyll/entry_filter.rb +++ b/lib/jekyll/entry_filter.rb @@ -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) || diff --git a/test/test_entry_filter.rb b/test/test_entry_filter.rb index 8d7b154d2ab..fc0dfeb2e9d 100644 --- a/test/test_entry_filter.rb +++ b/test/test_entry_filter.rb @@ -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)