Sha256: 523bed817a3096003b7cf48337c96b730b6b640809cfba5d77b9ccbc2749beca

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

require 'brakeman/processors/base_processor'

#Base Processor for templates/views
class Brakeman::TemplateProcessor < Brakeman::BaseProcessor

  #Initializes template information.
  def initialize tracker, template_name, called_from = nil, file_name = nil
    super(tracker) 
    @current_template = { :name => template_name,
                          :caller => called_from,
                          :partial => template_name.to_s[0,1] == "_",
                          :outputs => [],
                          :src => nil, #set in Processor
                          :type => nil, #set in Processor
                          :file => file_name } 
    if called_from
      template_name = (template_name.to_s + "." + called_from.to_s).to_sym
    end

    tracker.templates[template_name] = @current_template

    @inside_concat = false
  end

  #Process the template Sexp.
  def process exp
    begin
      super
    rescue Exception => e
      except = e.exception("Error when processing #{@current_template[:name]}: #{e.message}")
      except.set_backtrace(e.backtrace)
      raise except
    end
  end

  #Ignore initial variable assignment
  def process_lasgn exp
    if exp.lhs == :_erbout and exp.rhs.node_type == :str  #ignore
      ignore
    elsif exp.lhs == :_buf and exp.rhs.node_type == :str
      ignore
    else
      exp.rhs = process exp.rhs
      exp
    end
  end

  #Adds output to the list of outputs.
  def process_output exp
    process exp.value
    @current_template[:outputs] << exp
    exp
  end

  def process_escaped_output exp
    process_output exp
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
brakeman-1.9.4 lib/brakeman/processors/template_processor.rb
brakeman-1.9.3 lib/brakeman/processors/template_processor.rb
brakeman-1.9.2 lib/brakeman/processors/template_processor.rb
brakeman-1.9.1 lib/brakeman/processors/template_processor.rb
brakeman-1.9.0 lib/brakeman/processors/template_processor.rb
brakeman-1.9.0.pre2 lib/brakeman/processors/template_processor.rb
brakeman-1.9.0.pre1 lib/brakeman/processors/template_processor.rb
brakeman-1.8.3 lib/brakeman/processors/template_processor.rb
brakeman-1.8.2 lib/brakeman/processors/template_processor.rb
brakeman-1.8.1 lib/brakeman/processors/template_processor.rb
brakeman-1.8.0 lib/brakeman/processors/template_processor.rb