lib/brakeman/processors/alias_processor.rb in brakeman-3.6.2 vs lib/brakeman/processors/alias_processor.rb in brakeman-3.7.0
- old
+ new
@@ -85,10 +85,77 @@
else
exp
end
end
+ def process_bracket_call exp
+ r = replace(exp)
+
+ if r != exp
+ return r
+ end
+
+ exp.arglist = process_default(exp.arglist)
+
+ r = replace(exp)
+
+ if r != exp
+ return r
+ end
+
+ t = process(exp.target.deep_clone)
+
+ # sometimes t[blah] has a match in the env
+ # but we don't want to actually set the target
+ # in case the target is big...which is what this
+ # whole method is trying to avoid
+ if t != exp.target
+ e = exp.deep_clone
+ e.target = t
+
+ r = replace(e)
+
+ if r != e
+ return r
+ end
+ else
+ t = nil
+ end
+
+ if hash? t
+ if v = hash_access(t, exp.first_arg)
+ v.deep_clone(exp.line)
+ else
+ case t.node_type
+ when :params
+ exp.target = PARAMS_SEXP.deep_clone(exp.target.line)
+ when :session
+ exp.target = SESSION_SEXP.deep_clone(exp.target.line)
+ when :cookies
+ exp.target = COOKIES_SEXP.deep_clone(exp.target.line)
+ end
+
+ exp
+ end
+ elsif array? t
+ if v = process_array_access(t, exp.args)
+ v.deep_clone(exp.line)
+ else
+ exp
+ end
+ elsif t
+ exp.target = t
+ exp
+ else
+ if exp.target # `self` target is reported as `nil` https://github.com/seattlerb/ruby_parser/issues/250
+ exp.target = process_default exp.target
+ end
+
+ exp
+ end
+ end
+
ARRAY_CONST = s(:const, :Array)
HASH_CONST = s(:const, :Hash)
RAILS_TEST = s(:call, s(:call, s(:const, :Rails), :env), :test?)
#Process a method call.
@@ -97,12 +164,17 @@
target_var = exp.target
target_var &&= target_var.deep_clone
if exp.node_type == :safe_call
exp.node_type = :call
end
- exp = process_default exp
+ if exp.method == :[]
+ return process_bracket_call exp
+ else
+ exp = process_default exp
+ end
+
#In case it is replaced with something else
unless call? exp
return exp
end
@@ -389,11 +461,11 @@
# x.y = 1
#or
# x[:y] = 1
def process_attrasgn exp
tar_variable = exp.target
- target = exp.target = process(exp.target)
+ target = process(exp.target)
method = exp.method
index_arg = exp.first_arg
value_arg = exp.second_arg
if method == :[]=
@@ -404,17 +476,22 @@
set_value match, value
if hash? target
env[tar_variable] = hash_insert target.deep_clone, index, value
end
+
+ unless node_type? target, :hash
+ exp.target = target
+ end
elsif method.to_s[-1,1] == "="
exp.first_arg = process(index_arg)
value = get_rhs(exp)
#This is what we'll replace with the value
match = Sexp.new(:call, target, method.to_s[0..-2].to_sym)
set_value match, value
+ exp.target = target
else
raise "Unrecognized assignment: #{exp}"
end
exp
end
@@ -520,11 +597,18 @@
def process_cdecl exp
if sexp? exp.rhs
exp.rhs = process exp.rhs
end
- @tracker.add_constant exp.lhs, exp.rhs, :file => current_file_name if @tracker
+ if @tracker
+ @tracker.add_constant exp.lhs,
+ exp.rhs,
+ :file => current_file_name,
+ :module => @current_module,
+ :class => @current_class,
+ :method => @current_method
+ end
if exp.lhs.is_a? Symbol
match = Sexp.new(:const, exp.lhs)
else
match = exp.lhs
@@ -596,9 +680,13 @@
var = condition.first_arg
previous_value = env.current[var]
env.current[var] = condition.target[1]
exp[branch_index] = process_if_branch branch
env.current[var] = previous_value
+ elsif i == 1 and array_include_all_literals? condition and node_type? branch, :return
+ var = condition.first_arg
+ env.current[var] = condition.target[1]
+ exp[branch_index] = process_if_branch branch
else
exp[branch_index] = process_if_branch branch
end
branch_scopes << env.current
@branch_env = nil