module Rack
  class Bug
    module FilteredBacktrace

      def backtrace
        @backtrace
      end

      def has_backtrace?
        filtered_backtrace.any?
      end

      def filtered_backtrace
        @filtered_backtrace ||= @backtrace.map{|l| l.to_s.strip }.select do |line|
          root_for_backtrace_filtering.nil? ||
          (line.index(root_for_backtrace_filtering) == 0) && !(line.index(root_for_backtrace_filtering("vendor")) == 0)
        end
      end

      def root_for_backtrace_filtering(sub_path = nil)
        if defined?(Rails) && Rails.respond_to?(:root)
          sub_path ? Rails.root.join(sub_path) : Rails.root
        else
          root = if defined?(RAILS_ROOT)
            RAILS_ROOT
          elsif defined?(ROOT)
            ROOT
          elsif defined?(Sinatra::Application)
            Sinatra::Application.root
          else
            nil
          end
          sub_path ? ::File.join(root, sub_path) : root
        end
      end
    end
  end
end

module Rack
  class Bug
    module FilteredBacktrace

      def backtrace
        @backtrace
      end

      def has_backtrace?
        filtered_backtrace.any?
      end

      def filtered_backtrace
        @filtered_backtrace ||= @backtrace.map{|l| l.to_s.strip }.select do |line|
          root_for_backtrace_filtering.nil? ||
          (line.index(root_for_backtrace_filtering) == 0) && !(line.index(root_for_backtrace_filtering("vendor")) == 0)
        end
      end

      def root_for_backtrace_filtering(sub_path = nil)
        if defined?(Rails) && Rails.respond_to?(:root)
          sub_path ? Rails.root.join(sub_path) : Rails.root
        else
          root = if defined?(RAILS_ROOT)
            RAILS_ROOT
          elsif defined?(ROOT)
            ROOT
          elsif defined?(Sinatra::Application)
            Sinatra::Application.root
          else
            nil
          end
          sub_path ? ::File.join(root, sub_path) : root
        end.to_s
      end
    end
  end
end

Fix for type mismatch: Pathname given
Fix for type mismatch: Pathname given

  lib/rack/bug/filtered_backtrace.rb:16:in `index'
