Class: Brakeman::RouteAliasProcessor

Inherits:
AliasProcessor 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.

Constant Summary

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from AliasProcessor

#result

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from AliasProcessor

#duplicate?, #find_push_target, #initialize, #join_arrays, #join_strings, #only_ivars, #process_array_access, #process_attrasgn, #process_block, #process_cdecl, #process_cvdecl, #process_default, #process_gasgn, #process_hash_access, #process_hash_merge, #process_hash_merge!, #process_iasgn, #process_if, #process_lasgn, #process_methdef, #process_op_asgn1, #process_op_asgn2, #process_safely, #process_scope, #process_selfdef, #process_svalue, #set_line

Methods included from Util

#array?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #node_type?, #number?, #params?, #pluralize, #regexp?, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#class_name, #process_all, #process_module

Methods inherited from SexpProcessor

#error_handler, #in_context, #initialize, #process, #process_dummy, #scope

Constructor Details

This class inherits a constructor from Brakeman::AliasProcessor

Instance Method Details

#get_keys(hash) ⇒ Object

Returns an array Sexp containing the keys from the hash



299
300
301
302
303
304
305
306
# File 'lib/brakeman/processors/lib/rails2_route_processor.rb', line 299

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


285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/brakeman/processors/lib/rails2_route_processor.rb', line 285

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