lib/brakeman/processors/lib/find_call.rb in brakeman-1.7.1 vs lib/brakeman/processors/lib/find_call.rb in brakeman-1.8.0

- old
+ new

@@ -1,8 +1,10 @@ require 'brakeman/processors/base_processor' #Finds method calls matching the given target(s). +# #-- This should be deprecated --# +# #-- Do not use for new code --# # #Targets/methods can be: # # - nil: matches anything, including nothing # - Empty array: matches nothing @@ -65,33 +67,26 @@ process exp end #Process body of method def process_methdef exp - process exp[3] + process exp.body end - #Process body of method - def process_selfdef exp - process exp[4] - end + alias :process_selfdef :process_methdef #Process body of block def process_rlist exp - exp[1..-1].each do |e| - process e - end - - exp + process_all exp end #Look for matching calls and add them to results def process_call exp - target = get_target exp[1] - method = exp[2] + target = get_target exp.target + method = exp.method - process exp[3] + process_all exp.args if match(@find_targets, target) and match(@find_methods, method) if @current_template @calls << Sexp.new(:result, @current_template, exp).line(exp.line) @@ -105,12 +100,12 @@ #another call, such as: # # User.find(:first, :conditions => "user = '#{params['user']}').name # #A search for User.find will not match this unless @in_depth is true. - if @in_depth and node_type? exp[1], :call - process exp[1] + if @in_depth and node_type? exp.target, :call + process exp.target end exp end @@ -124,16 +119,14 @@ #Gets the target of a call as a Symbol #if possible def get_target exp if sexp? exp case exp.node_type - when :ivar, :lvar, :const - exp[1] + when :ivar, :lvar, :const, :lit + exp.value when :true, :false - exp[0] - when :lit - exp[1] + exp.node_type when :colon2 class_name exp else exp end @@ -174,13 +167,13 @@ end #Checks if +item+ is an instance of +klass+ by looking for Klass.new def is_instance_of? item, klass if call? item - if sexp? item[1] - item[2] == :new and item[1].node_type == :const and item[1][1] == klass + if sexp? item.target + item.method == :new and item.target.node_type == :const and item.target.value == klass else - item[2] == :new and item[1] == klass + item.method == :new and item.target == klass end else false end end