From 20735e12f9ea1ffd49294bb8e5bf3ec724853dc6 Mon Sep 17 00:00:00 2001 From: Ducksan Cho Date: Thu, 19 Nov 2015 01:02:48 +1300 Subject: [PATCH] Use safe_glob to unsafe glob --- lib/jekyll/cleaner.rb | 11 +++-------- lib/jekyll/collection.rb | 7 ++----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index a8bbf24e..9146e7de 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -36,18 +36,13 @@ 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.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 + Utils.safe_glob(site.in_dest_dir, "**/*", File::FNM_DOTMATCH).each do |file| + next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file) + files << file end files diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index 4d4b9bd0..e4725718 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -74,11 +74,8 @@ module Jekyll def entries return Array.new unless exists? @entries ||= - Dir.chdir(collection_dir) do - Dir.glob("**/*.*").map do |f| - entry = collection_dir(f) - entry["#{collection_dir}/"] = ''; entry - end + Utils.safe_glob(collection_dir, "**/*.*").map do |entry| + entry["#{collection_dir}/"] = ''; entry end end