提交 820ba362 编写于 作者: J Justin Collins

Use Util.node_type? wherever possible

instead of "sexp? exp and exp.node_type == :blah"
or "sexp? exp and exp[0] == :blah"
上级 e69ace89
...@@ -35,7 +35,11 @@ class Brakeman::CheckLinkToHref < Brakeman::CheckLinkTo ...@@ -35,7 +35,11 @@ class Brakeman::CheckLinkToHref < Brakeman::CheckLinkTo
call = result[:call] = result[:call].dup call = result[:call] = result[:call].dup
@matched = false @matched = false
url_arg = process call[3][2] url_arg = process call[3][2]
return if sexp?(url_arg) && url_arg.node_type == :string_interp && !url_arg[1].chomp.empty?
#Ignore situations where the href is an interpolated string
#with something before the user input
return if node_type?(url_arg, :string_interp) && !url_arg[1].chomp.empty?
type, match = has_immediate_user_input? url_arg type, match = has_immediate_user_input? url_arg
if type if type
......
...@@ -181,7 +181,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck ...@@ -181,7 +181,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
arg.each do |exp| arg.each do |exp|
#For now, don't warn on interpolation of Model.table_name #For now, don't warn on interpolation of Model.table_name
#but check for other 'safe' things in the future #but check for other 'safe' things in the future
if sexp? exp and (exp.node_type == :string_eval or exp.node_type == :evstr) if node_type? exp, :string_eval, :evstr
if call? exp[1] and (model_name?(exp[1][1]) or exp[1][1].nil?) and exp[1][2] == :table_name if call? exp[1] and (model_name?(exp[1][1]) or exp[1][1].nil?) and exp[1][2] == :table_name
return false return false
end end
......
...@@ -85,7 +85,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor ...@@ -85,7 +85,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor
else else
Brakeman.debug "[Notice] Layout not found: #{name}" Brakeman.debug "[Notice] Layout not found: #{name}"
end end
elsif sexp? args[-1] and (args[-1][0] == :nil or args[-1][0] == :false) elsif node_type? args[-1], :nil, :false
#layout :false or layout nil #layout :false or layout nil
@controller[:layout] = false @controller[:layout] = false
end end
...@@ -181,7 +181,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor ...@@ -181,7 +181,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor
block_variable = :temp block_variable = :temp
end end
if sexp? exp[3] and exp[3].node_type == :block if node_type? exp[3], :block
block_inner = exp[3][1..-1] block_inner = exp[3][1..-1]
else else
block_inner = [exp[3]] block_inner = [exp[3]]
......
...@@ -68,7 +68,7 @@ class Brakeman::ErbTemplateProcessor < Brakeman::TemplateProcessor ...@@ -68,7 +68,7 @@ class Brakeman::ErbTemplateProcessor < Brakeman::TemplateProcessor
res = process e res = process e
if res.empty? or res == ignore if res.empty? or res == ignore
nil nil
elsif sexp? res and res.node_type == :lvar and res[1] == :_erbout elsif node_type?(res, :lvar) and res[1] == :_erbout
nil nil
else else
......
...@@ -138,7 +138,7 @@ class Brakeman::FindAllCalls < Brakeman::BaseProcessor ...@@ -138,7 +138,7 @@ class Brakeman::FindAllCalls < Brakeman::BaseProcessor
#Returns method chain as an array #Returns method chain as an array
#For example, User.human.alive.all would return [:User, :human, :alive, :all] #For example, User.human.alive.all would return [:User, :human, :alive, :all]
def get_chain call def get_chain call
if sexp? call and (call.node_type == :call or call.node_type == :attrasgn) if node_type? call, :call, :attrasgn
get_chain(call[1]) + [call[2]] get_chain(call[1]) + [call[2]]
else else
[get_target(call)] [get_target(call)]
......
...@@ -107,7 +107,7 @@ class Brakeman::FindCall < Brakeman::BaseProcessor ...@@ -107,7 +107,7 @@ class Brakeman::FindCall < Brakeman::BaseProcessor
# User.find(:first, :conditions => "user = '#{params['user']}').name # User.find(:first, :conditions => "user = '#{params['user']}').name
# #
#A search for User.find will not match this unless @in_depth is true. #A search for User.find will not match this unless @in_depth is true.
if @in_depth and sexp? exp[1] and exp[1][0] == :call if @in_depth and node_type? exp[1], :call
process exp[1] process exp[1]
end end
......
...@@ -103,7 +103,7 @@ class Brakeman::Rails2ConfigProcessor < Brakeman::BaseProcessor ...@@ -103,7 +103,7 @@ class Brakeman::Rails2ConfigProcessor < Brakeman::BaseProcessor
# #
# [:action_controller, :session_store] # [:action_controller, :session_store]
def get_rails_config exp def get_rails_config exp
if sexp? exp and exp.node_type == :attrasgn if node_type? exp, :attrasgn
attribute = exp[2].to_s[0..-2].to_sym attribute = exp[2].to_s[0..-2].to_sym
get_rails_config(exp[1]) << attribute get_rails_config(exp[1]) << attribute
elsif call? exp elsif call? exp
......
...@@ -89,7 +89,7 @@ class Brakeman::Rails2RoutesProcessor < Brakeman::BaseProcessor ...@@ -89,7 +89,7 @@ class Brakeman::Rails2RoutesProcessor < Brakeman::BaseProcessor
process_resource_options exp[-1] process_resource_options exp[-1]
else else
exp.each do |argument| exp.each do |argument|
if sexp? argument and argument.node_type == :lit if node_type? argument, :lit
self.current_controller = exp[0][1] self.current_controller = exp[0][1]
add_resources_routes add_resources_routes
process_resource_options exp[-1] process_resource_options exp[-1]
...@@ -165,7 +165,7 @@ class Brakeman::Rails2RoutesProcessor < Brakeman::BaseProcessor ...@@ -165,7 +165,7 @@ class Brakeman::Rails2RoutesProcessor < Brakeman::BaseProcessor
process_resource_options exp[-1] process_resource_options exp[-1]
else else
exp.each do |argument| exp.each do |argument|
if sexp? argument and argument.node_type == :lit if node_type? argument, :lit
self.current_controller = pluralize(exp[0][1].to_s) self.current_controller = pluralize(exp[0][1].to_s)
add_resource_routes add_resource_routes
process_resource_options exp[-1] process_resource_options exp[-1]
......
...@@ -29,7 +29,7 @@ class Brakeman::Rails3ConfigProcessor < Brakeman::BaseProcessor ...@@ -29,7 +29,7 @@ class Brakeman::Rails3ConfigProcessor < Brakeman::BaseProcessor
#Look for MyApp::Application.configure do ... end #Look for MyApp::Application.configure do ... end
def process_iter exp def process_iter exp
if sexp?(exp[1][1]) and exp[1][1][0] == :colon2 and exp[1][1][2] == :Application if node_type?(exp[1][1], :colon2) and exp[1][1][2] == :Application
@inside_config = true @inside_config = true
process exp[-1] if sexp? exp[-1] process exp[-1] if sexp? exp[-1]
@inside_config = false @inside_config = false
...@@ -100,7 +100,7 @@ class Brakeman::Rails3ConfigProcessor < Brakeman::BaseProcessor ...@@ -100,7 +100,7 @@ class Brakeman::Rails3ConfigProcessor < Brakeman::BaseProcessor
# #
# [:action_controller, :session_store] # [:action_controller, :session_store]
def get_rails_config exp def get_rails_config exp
if sexp? exp and exp.node_type == :attrasgn if node_type? exp, :attrasgn
attribute = exp[2].to_s[0..-2].to_sym attribute = exp[2].to_s[0..-2].to_sym
get_rails_config(exp[1]) << attribute get_rails_config(exp[1]) << attribute
elsif call? exp elsif call? exp
......
...@@ -75,7 +75,7 @@ module Brakeman::RenderHelper ...@@ -75,7 +75,7 @@ module Brakeman::RenderHelper
#Process layout #Process layout
if string? options[:layout] if string? options[:layout]
process_template "layouts/#{options[:layout][1]}", nil process_template "layouts/#{options[:layout][1]}", nil
elsif sexp? options[:layout] and options[:layout][0] == :false elsif node_type? options[:layout], :false
#nothing #nothing
elsif not template[:name].to_s.match(/[^\/_][^\/]+$/) elsif not template[:name].to_s.match(/[^\/_][^\/]+$/)
#Don't do this for partials #Don't do this for partials
......
...@@ -40,7 +40,7 @@ class Brakeman::TemplateAliasProcessor < Brakeman::AliasProcessor ...@@ -40,7 +40,7 @@ class Brakeman::TemplateAliasProcessor < Brakeman::AliasProcessor
#Check for e.g. Model.find.each do ... end #Check for e.g. Model.find.each do ... end
if method == :each and args and block and model = get_model_target(target) if method == :each and args and block and model = get_model_target(target)
if sexp? args and args.node_type == :lasgn if node_type? args, :lasgn
if model == target[1] if model == target[1]
env[Sexp.new(:lvar, args[1])] = Sexp.new(:call, model, :new, Sexp.new(:arglist)) env[Sexp.new(:lvar, args[1])] = Sexp.new(:call, model, :new, Sexp.new(:arglist))
else else
...@@ -50,7 +50,7 @@ class Brakeman::TemplateAliasProcessor < Brakeman::AliasProcessor ...@@ -50,7 +50,7 @@ class Brakeman::TemplateAliasProcessor < Brakeman::AliasProcessor
process block if sexp? block process block if sexp? block
end end
elsif FORM_METHODS.include? method elsif FORM_METHODS.include? method
if sexp? args and args.node_type == :lasgn if node_type? args, :lasgn
env[Sexp.new(:lvar, args[1])] = Sexp.new(:call, Sexp.new(:const, :FormBuilder), :new, Sexp.new(:arglist)) env[Sexp.new(:lvar, args[1])] = Sexp.new(:call, Sexp.new(:const, :FormBuilder), :new, Sexp.new(:arglist))
process block if sexp? block process block if sexp? block
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册