Class: Brakeman::TemplateProcessor

Inherits:
BaseProcessor show all
Defined in:
lib/brakeman/processors/template_processor.rb

Overview

Base Processor for templates/views

Constant Summary

Constants inherited from BaseProcessor

BaseProcessor::IGNORE

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from BaseProcessor

#find_render_type, #ignore, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_default, #process_dstr, #process_evstr, #process_hash, #process_if, #process_ignore, #process_iter, #process_scope

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#process_all, #process_all!, #process_call_args, #process_call_defn?, #process_class, #process_module

Methods inherited from SexpProcessor

#in_context, processors, #scope

Constructor Details

#initialize(tracker, template_name, called_from = nil, file_name = nil) ⇒ TemplateProcessor

Initializes template information.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/brakeman/processors/template_processor.rb', line 8

def initialize tracker, template_name, called_from = nil, file_name = nil
  super(tracker) 
  @current_template = Brakeman::Template.new template_name, called_from, file_name, tracker

  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

Instance Method Details

#process(exp) ⇒ Object

Process the template Sexp.



22
23
24
25
26
27
28
29
30
# File 'lib/brakeman/processors/template_processor.rb', line 22

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

#process_escaped_output(exp) ⇒ Object



51
52
53
# File 'lib/brakeman/processors/template_processor.rb', line 51

def process_escaped_output exp
  process_output exp
end

#process_lasgn(exp) ⇒ Object

Ignore initial variable assignment



33
34
35
36
37
38
39
40
41
42
# File 'lib/brakeman/processors/template_processor.rb', line 33

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

#process_output(exp) ⇒ Object

Adds output to the list of outputs.



45
46
47
48
49
# File 'lib/brakeman/processors/template_processor.rb', line 45

def process_output exp
  exp.value = process exp.value
  @current_template.add_output exp unless exp.original_line
  exp
end