lib/file/find.rb in file-find-0.4.4 vs lib/file/find.rb in file-find-0.5.0

- old
+ new

@@ -7,11 +7,11 @@ # Do nothing, not required, just nicer. end class File::Find # The version of the file-find library - VERSION = '0.4.4'.freeze + VERSION = '0.5.0'.freeze # :stopdoc: VALID_OPTIONS = %w[ atime ctime @@ -239,12 +239,13 @@ stat_method = :lstat # Handle recursive symlinks retry end end - # We need to escape any brackets in the directory name. - glob = File.join(File.dirname(file).gsub(/([\[\]])/,'\\\\\1'), @name) + # We need to escape any brackets in the directory name, unless already escaped. + temp = File.dirname(file).gsub(/(?<!\\)([\[\]])/, '\\\\\1') + glob = File.join(temp, @name) # Dir[] doesn't like backslashes if File::ALT_SEPARATOR file.tr!(File::ALT_SEPARATOR, File::SEPARATOR) glob.tr!(File::ALT_SEPARATOR, File::SEPARATOR) @@ -257,10 +258,10 @@ if @links next unless stat_info.nlink == @links end if @maxdepth || @mindepth - file_depth = file.split(File::SEPARATOR).length + file_depth = file.split(File::SEPARATOR).reject{ |e| e.size.zero? }.length current_base_path = [@path].flatten.find{ |tpath| file.include?(tpath) } path_depth = current_base_path.split(File::SEPARATOR).length depth = file_depth - path_depth