Sha256: 995b59baeeba71631dc6b91680c56ef60fa0edcf3aef2d1206b358482205c706

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'set'

module TaintedLove
  module Reporter
    # Base reporter
    class Base
      attr_reader :warnings

      def initialize
        @warnings = Hash.new do |h, k|
          h[k] = {
            stack_trace: nil,
            replacer: nil,
            inputs: {},
            tags: [],
            message: nil,
          }
        end
      end

      # Stores a warning by its stack trace hash
      #
      # @param warning [TaintedLove::Warning]
      def store_warning(warning)
        key = warning.stack_trace.trace_hash

        @warnings[key].merge!(
          replacer: warning.replacer,
          stack_trace: warning.stack_trace.lines,
          tags: warning.tags,
          message: warning.message,
        )

        @warnings[key][:inputs][warning.tainted_input] = {
          reported_at: warning.reported_at,
          taint_tags: warning.tainted_input.tainted_love_tags.uniq
        }
      end

      # Adds a warning to the reporter
      #
      # @param warning [TaintedLove::Warning]
      def add_warning(warning)
        store_warning(warning)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tainted_love-0.4.1 lib/tainted_love/reporter/base.rb
tainted_love-0.4.0 lib/tainted_love/reporter/base.rb