diff --git a/lib/cocoapods/sandbox/path_list.rb b/lib/cocoapods/sandbox/path_list.rb index 6fb6630aa0..107efff596 100644 --- a/lib/cocoapods/sandbox/path_list.rb +++ b/lib/cocoapods/sandbox/path_list.rb @@ -54,7 +54,8 @@ def read_file_system dirs = [] files = [] root_length = root.cleanpath.to_s.length + File::SEPARATOR.length - Dir.glob(root + '**/*', File::FNM_DOTMATCH).each do |f| + escaped_root = escape_path_for_glob(root) + Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH).each do |f| directory = File.directory?(f) # Ignore `.` and `..` directories next if directory && f =~ /\.\.?$/ @@ -216,6 +217,25 @@ def dir_glob_equivalent_patterns(pattern) end end + # Escapes the glob metacharacters from a given path so it can used in + # Dir#glob and similar methods. + # + # @note See CocoaPods/CocoaPods#862. + # + # @param [String, Pathname] path + # The path to escape. + # + # @return [Pathname] The escaped path. + # + def escape_path_for_glob(path) + result = path.to_s + characters_to_escape = ['[', ']', '{', '}', '?', '*'] + characters_to_escape.each do |character| + result.gsub!(character, "\\#{character}") + end + Pathname.new(result) + end + #-----------------------------------------------------------------------# end end