From 6171a6b73e2faae7c68a0140f6e998a3dadcdf87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Mon, 23 Dec 2019 19:14:51 +0300 Subject: [PATCH] Revert escaping logic for metacharacters --- lib/cocoapods/sandbox/path_list.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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