From 70870328bffc38c44652e7b1d4568fcf35d8b351 Mon Sep 17 00:00:00 2001 From: Billy Kong Date: Mon, 27 Apr 2020 22:06:05 +0800 Subject: [PATCH] Config include trailing slash (#8113) Merge pull request 8113 --- lib/jekyll/entry_filter.rb | 3 ++- test/source/_glob_include_test/_is_dir/include_me.txt | 0 test/source/_glob_include_test/_not_dir | 0 test/test_entry_filter.rb | 7 +++++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/source/_glob_include_test/_is_dir/include_me.txt create mode 100644 test/source/_glob_include_test/_not_dir diff --git a/lib/jekyll/entry_filter.rb b/lib/jekyll/entry_filter.rb index 4f527edd..a7ece193 100644 --- a/lib/jekyll/entry_filter.rb +++ b/lib/jekyll/entry_filter.rb @@ -98,7 +98,8 @@ module Jekyll pattern_with_source = PathManager.join(site.source, pattern) File.fnmatch?(pattern_with_source, entry_with_source) || - entry_with_source.start_with?(pattern_with_source) + entry_with_source.start_with?(pattern_with_source) || + (pattern_with_source == "#{entry_with_source}/" if File.directory?(entry_with_source)) when Regexp pattern.match?(entry_with_source) else diff --git a/test/source/_glob_include_test/_is_dir/include_me.txt b/test/source/_glob_include_test/_is_dir/include_me.txt new file mode 100644 index 00000000..e69de29b diff --git a/test/source/_glob_include_test/_not_dir b/test/source/_glob_include_test/_not_dir new file mode 100644 index 00000000..e69de29b diff --git a/test/test_entry_filter.rb b/test/test_entry_filter.rb index b3d820e0..8d7b154d 100644 --- a/test/test_entry_filter.rb +++ b/test/test_entry_filter.rb @@ -149,5 +149,12 @@ class TestEntryFilter < JekyllUnitTest assert @filter.glob_include?(data, "vendor/bundle/jekyll/lib/page.rb") assert @filter.glob_include?(data, "/vendor/ruby/lib/set.rb") end + + should "match directory only if there is trailing slash" do + data = ["_glob_include_test/_is_dir/", "_glob_include_test/_not_dir/"] + assert @filter.glob_include?(data, "_glob_include_test/_is_dir") + assert @filter.glob_include?(data, "_glob_include_test/_is_dir/include_me.txt") + refute @filter.glob_include?(data, "_glob_include_test/_not_dir") + end end end