class TaintedLove::StackTrace

Constants

BACKTRACE_LINE_REGEX

Attributes

lines[RW]
stack_trace[RW]

Public Class Methods

current(skip = 2) click to toggle source

Create a new StackTrace object from the current thread backtrace

@param skip [Integer] number of trace line to skip @return [TaintedLove::StackTrace]

# File lib/tainted_love/stack_trace.rb, line 42
def self.current(skip = 2)
  new(Thread.current.backtrace(skip))
end
new(stack_trace) click to toggle source
# File lib/tainted_love/stack_trace.rb, line 9
def initialize(stack_trace)
  @stack_trace = stack_trace
  @lines = stack_trace.map do |line|
    next unless line.match(BACKTRACE_LINE_REGEX)
    {
      file: Regexp.last_match(1),
      line_number: Regexp.last_match(2).to_i,
      method: Regexp.last_match(3),
    }
  end.compact

  # Hack to remove TaintedLove.proxy_method
  @lines.shift if @lines.first[:file]['tainted_love/utils.rb']
end

Public Instance Methods

to_json() click to toggle source
# File lib/tainted_love/stack_trace.rb, line 32
def to_json
  {
    trace_hash: trace_hash,
  }.to_json
end
trace_hash() click to toggle source

Produces a hash from the stack trace to identify identical code path

@return [String]

# File lib/tainted_love/stack_trace.rb, line 27
def trace_hash
  lines = @lines.map { |line| "#{line[:file]}:#{line[:number]}" }.join(',')
  TaintedLove.hash(lines)
end