Class: Brakeman::RouteAliasProcessor

Inherits:
AliasProcessor
  • Object
show all
Defined in:
lib/brakeman/processors/lib/rails2_route_processor.rb

Overview

This is for a really specific case where a hash is used as arguments to one of the map methods.

Instance Method Summary collapse

Instance Method Details

#get_keys(hash) ⇒ Object

Returns an array Sexp containing the keys from the hash



305
306
307
308
309
310
311
312
# File 'lib/brakeman/processors/lib/rails2_route_processor.rb', line 305

def get_keys hash
  keys = Sexp.new(:array)
  hash_iterate(hash) do |key, _value|
    keys << key
  end

  keys
end

#process_call(exp) ⇒ Object

This replaces { :some => :hash }.keys with [:some]



291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/brakeman/processors/lib/rails2_route_processor.rb', line 291

def process_call exp
  process_default exp

  if hash? exp.target and exp.method == :keys
    keys = get_keys exp.target
    exp.clear
    keys.each_with_index do |e,i|
      exp[i] = e
    end
  end
  exp
end