From bd2c337e5bd1a3532f42776f55f80f4e273cfeac Mon Sep 17 00:00:00 2001 From: Ducksan Cho Date: Wed, 18 Nov 2015 02:16:03 +1300 Subject: [PATCH] Avoid using Dir.glob with absolute path the absolute path including '[', '{', '?', or '*' could change the outcome --- lib/jekyll/cleaner.rb | 11 ++++++++--- lib/jekyll/collection.rb | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index d23da78f..a8bbf24e 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -36,13 +36,18 @@ module Jekyll # # Returns a Set with the file paths def existing_files + return Set.new unless Dir.exist?(site.in_dest_dir) + files = Set.new regex = keep_file_regex dirs = keep_dirs - Dir.glob(site.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file| - next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file) - files << file + Dir.chdir(site.in_dest_dir) do + Dir.glob("**/*", File::FNM_DOTMATCH).each do |f| + file = File.join(site.in_dest_dir, f) + next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file) + files << file + end end files diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index 4363aee1..4d4b9bd0 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -74,8 +74,11 @@ module Jekyll def entries return Array.new unless exists? @entries ||= - Dir.glob(collection_dir("**", "*.*")).map do |entry| - entry["#{collection_dir}/"] = ''; entry + Dir.chdir(collection_dir) do + Dir.glob("**/*.*").map do |f| + entry = collection_dir(f) + entry["#{collection_dir}/"] = ''; entry + end end end