Class: Brakeman::BaseProcessor
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- Brakeman::BaseProcessor
- Includes:
- ProcessorHelper, Util
- Defined in:
- lib/brakeman/processors/base_processor.rb
Overview
Base processor for most processors.
Direct Known Subclasses
ControllerProcessor, FindAllCalls, FindCall, GemProcessor, LibraryProcessor, ModelProcessor, Rails2ConfigProcessor, Rails2RoutesProcessor, Rails3ConfigProcessor, Rails3RoutesProcessor, TemplateProcessor
Constant Summary
Constant Summary
Constants included from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_PARAMETERS, Util::SESSION
Instance Attribute Summary (collapse)
-
- (Object) ignore
readonly
Returns the value of attribute ignore.
Instance Method Summary (collapse)
-
- (Object) find_render_type(args)
Determines the type of a call to render.
-
- (BaseProcessor) initialize(tracker)
constructor
Return a new Processor.
-
- (Object) make_render(exp)
Generates :render node from call to render.
-
- (Object) process_and(exp)
Processes an and keyword.
-
- (Object) process_arglist(exp)
Processes the values in an argument list.
-
- (Object) process_attrasgn(exp)
Processes an attribute assignment, which can be either x.y = 1 or x = 1.
-
- (Object) process_block(exp)
Processes a block.
-
- (Object) process_default(exp)
Default processing.
-
- (Object) process_dstr(exp)
String with interpolation.
-
- (Object) process_evstr(exp)
Processes the inside of an interpolated String.
-
- (Object) process_hash(exp)
Processes a hash.
-
- (Object) process_iasgn(exp)
Processes an instance variable assignment.
-
- (Object) process_if(exp)
Process an if statement.
-
- (Object) process_ignore(exp)
Ignore ignore Sexps.
-
- (Object) process_iter(exp)
Processes calls with blocks.
-
- (Object) process_lasgn(exp)
Processes a local assignment.
-
- (Object) process_or(exp)
Processes an or keyword.
-
- (Object) process_scope(exp)
Process a new scope.
Methods included from Util
#array?, #call?, #camelize, #cookies?, #false?, #hash?, #hash_insert, #hash_iterate, #integer?, #number?, #params?, #pluralize, #regexp?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #true?, #underscore
Methods included from ProcessorHelper
Constructor Details
- (BaseProcessor) initialize(tracker)
Return a new Processor.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/brakeman/processors/base_processor.rb', line 14 def initialize tracker super() self.strict = false self.auto_shift_type = false self.require_empty = false self.default_method = :process_default self.warn_on_default = false @last = nil @tracker = tracker @ignore = Sexp.new :ignore @current_template = @current_module = @current_class = @current_method = nil end |
Instance Attribute Details
- (Object) ignore (readonly)
Returns the value of attribute ignore
11 12 13 |
# File 'lib/brakeman/processors/base_processor.rb', line 11 def ignore @ignore end |
Instance Method Details
- (Object) find_render_type(args)
Determines the type of a call to render.
Possible types are: :action, :default :file, :inline, :js, :json, :nothing, :partial, :template, :text, :update, :xml
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/brakeman/processors/base_processor.rb', line 211 def find_render_type args rest = Sexp.new(:hash) type = nil value = nil if args.length == 2 and args[-1] == Sexp.new(:lit, :update) return :update, nil, args[0..-2] end #Look for render :action, ... or render "action", ... if string? args[1] or symbol? args[1] type = :action value = args[1] elsif args[1].is_a? Symbol or args[1].is_a? String type = :action value = Sexp.new(:lit, args[1].to_sym) elsif args[1].nil? type = :default elsif not hash? args[1] type = :action value = args[1] end if hash? args[-1] hash_iterate(args[-1]) do |key, val| case key[1] when :action, :file, :inline, :js, :json, :nothing, :partial, :text, :update, :xml type = key[1] value = val else rest << key << val end end end type ||= :default value ||= :default args[-1] = rest return type, value, rest end |
- (Object) make_render(exp)
Generates :render node from call to render.
198 199 200 201 202 203 204 |
# File 'lib/brakeman/processors/base_processor.rb', line 198 def make_render exp render_type, value, rest = find_render_type exp[3] rest = process rest result = Sexp.new(:render, render_type, value, rest) result.line(exp.line) result end |
- (Object) process_and(exp)
Processes an and keyword
137 138 139 140 141 142 |
# File 'lib/brakeman/processors/base_processor.rb', line 137 def process_and exp exp = exp.dup exp[1] = process exp[1] exp[2] = process exp[2] exp end |
- (Object) process_arglist(exp)
Processes the values in an argument list
160 161 162 163 164 165 166 167 168 |
# File 'lib/brakeman/processors/base_processor.rb', line 160 def process_arglist exp exp = exp.dup exp.shift exp.map! do |e| process e end exp.unshift :arglist end |
- (Object) process_attrasgn(exp)
Processes an attribute assignment, which can be either x.y = 1 or x = 1
185 186 187 188 189 190 |
# File 'lib/brakeman/processors/base_processor.rb', line 185 def process_attrasgn exp exp = exp.dup exp[1] = process exp[1] exp[3] = process exp[3] exp end |
- (Object) process_block(exp)
Processes a block. Changes Sexp node type to :rlist
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/brakeman/processors/base_processor.rb', line 108 def process_block exp exp = exp.dup exp.shift exp.map! do |e| process e end exp.unshift :rlist end |
- (Object) process_default(exp)
Default processing.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brakeman/processors/base_processor.rb', line 43 def process_default exp exp = exp.dup type = exp.shift exp.each_with_index do |e, i| if sexp? e and not e.empty? exp[i] = process e else e end end ensure exp.unshift type end |
- (Object) process_dstr(exp)
String with interpolation. Changes Sexp node type to :string_interp
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/brakeman/processors/base_processor.rb', line 86 def process_dstr exp exp = exp.dup exp.shift exp.map! do |e| if e.is_a? String e elsif e[1].is_a? String e[1] else res = process e if res.empty? nil else res end end end.compact! exp.unshift :string_interp end |
- (Object) process_evstr(exp)
Processes the inside of an interpolated String. Changes Sexp node type to :string_eval
121 122 123 124 125 126 |
# File 'lib/brakeman/processors/base_processor.rb', line 121 def process_evstr exp exp = exp.dup exp[0] = :string_eval exp[1] = process exp[1] exp end |
- (Object) process_hash(exp)
Processes a hash
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/brakeman/processors/base_processor.rb', line 145 def process_hash exp exp = exp.dup exp.shift exp.map! do |e| if sexp? e process e else e end end exp.unshift :hash end |
- (Object) process_iasgn(exp)
Processes an instance variable assignment
178 179 180 181 182 |
# File 'lib/brakeman/processors/base_processor.rb', line 178 def process_iasgn exp exp = exp.dup exp[2] = process exp[2] exp end |
- (Object) process_if(exp)
Process an if statement.
58 59 60 61 62 63 64 |
# File 'lib/brakeman/processors/base_processor.rb', line 58 def process_if exp exp = exp.dup exp[1] = process exp[1] exp[2] = process exp[2] if exp[2] exp[3] = process exp[3] if exp[3] exp end |
- (Object) process_ignore(exp)
Ignore ignore Sexps
193 194 195 |
# File 'lib/brakeman/processors/base_processor.rb', line 193 def process_ignore exp exp end |
- (Object) process_iter(exp)
Processes calls with blocks. Changes Sexp node type to :call_with_block
s(:iter, CALL, :lasgn|:masgn, BLOCK)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/brakeman/processors/base_processor.rb', line 69 def process_iter exp exp = exp.dup call = process exp[1] #deal with assignments somehow if exp[3] block = process exp[3] block = nil if block.empty? else block = nil end call = Sexp.new(:call_with_block, call, exp[2], block).compact call.line(exp.line) call end |
- (Object) process_lasgn(exp)
Processes a local assignment
171 172 173 174 175 |
# File 'lib/brakeman/processors/base_processor.rb', line 171 def process_lasgn exp exp = exp.dup exp[2] = process exp[2] exp end |
- (Object) process_or(exp)
Processes an or keyword
129 130 131 132 133 134 |
# File 'lib/brakeman/processors/base_processor.rb', line 129 def process_or exp exp = exp.dup exp[1] = process exp[1] exp[2] = process exp[2] exp end |
- (Object) process_scope(exp)
Process a new scope. Removes expressions that are set to nil.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/brakeman/processors/base_processor.rb', line 28 def process_scope exp exp = exp.dup exp.shift exp.map! do |e| res = process e if res.empty? res = nil else res end end.compact exp.unshift :scope end |