From 9720b4edf158ddefeccc60e56dea65870a54c2c9 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Thu, 23 Jul 2015 14:15:04 +0100 Subject: [PATCH] Escapes brackets etc potentially present in Dir.pwd When using Dir.glob - Fixes #840 --- lib/common/common_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/common/common_helper.rb b/lib/common/common_helper.rb index 966b9c0e..f51a2517 100644 --- a/lib/common/common_helper.rb +++ b/lib/common/common_helper.rb @@ -49,14 +49,18 @@ end require 'environment' +def escape_glob(s) + s.gsub(/[\\\{\}\[\]\*\?]/) { |x| '\\' + x } +end + # TODO : add an exclude pattern ? def require_files_from_directory(absolute_dir_path, files_pattern = '*.rb') - files = Dir[File.join(absolute_dir_path, files_pattern)] + files = Dir[File.join(escape_glob(absolute_dir_path), files_pattern)] # Files in the root dir are loaded first, then those in the subdirectories files.sort_by { |file| [file.count('/'), file] }.each do |f| f = File.expand_path(f) - #puts "require #{f}" # Used for debug + puts "require #{f}" # Used for debug require f end end