Escapes brackets etc potentially present in Dir.pwd When using Dir.glob - Fixes #840
This commit is contained in:
@@ -49,14 +49,18 @@ end
|
|||||||
|
|
||||||
require 'environment'
|
require 'environment'
|
||||||
|
|
||||||
|
def escape_glob(s)
|
||||||
|
s.gsub(/[\\\{\}\[\]\*\?]/) { |x| '\\' + x }
|
||||||
|
end
|
||||||
|
|
||||||
# TODO : add an exclude pattern ?
|
# TODO : add an exclude pattern ?
|
||||||
def require_files_from_directory(absolute_dir_path, files_pattern = '*.rb')
|
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 in the root dir are loaded first, then those in the subdirectories
|
||||||
files.sort_by { |file| [file.count('/'), file] }.each do |f|
|
files.sort_by { |file| [file.count('/'), file] }.each do |f|
|
||||||
f = File.expand_path(f)
|
f = File.expand_path(f)
|
||||||
#puts "require #{f}" # Used for debug
|
puts "require #{f}" # Used for debug
|
||||||
require f
|
require f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user