Class: TaintedLove::Reporter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tainted_love/reporter/base.rb

Overview

Base reporter

Direct Known Subclasses

FileReporter, StdoutReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tainted_love/reporter/base.rb', line 11

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

Instance Attribute Details

#warningsObject (readonly)

Returns the value of attribute warnings.



9
10
11
# File 'lib/tainted_love/reporter/base.rb', line 9

def warnings
  @warnings
end

Instance Method Details

#add_warning(warning) ⇒ Object

Adds a warning to the reporter

Parameters:



45
46
47
# File 'lib/tainted_love/reporter/base.rb', line 45

def add_warning(warning)
  store_warning(warning)
end

#store_warning(warning) ⇒ Object

Stores a warning by its stack trace hash

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tainted_love/reporter/base.rb', line 26

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