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 inherited from AliasProcessor

AliasProcessor::ARRAY_CONST, AliasProcessor::HASH_CONST, AliasProcessor::RAILS_TEST, AliasProcessor::STRING_NEW

Constants included from CallConversionHelper

CallConversionHelper::STRING_LENGTH_LIMIT

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from AliasProcessor

#result, #tracker

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from AliasProcessor

#array_detect_all_literals?, #array_include_all_literals?, #assign_args, #collapse_send_call, #duplicate?, #early_return?, #find_method, #find_push_target, #get_call_value, #get_rhs, #initialize, #join_item, #merge_if_branch, #meth_env, #new_string?, #only_ivars, #only_request_vars, #process_array_join, #process_attrasgn, #process_block, #process_bracket_call, #process_case, #process_cdecl, #process_cvdecl, #process_default, #process_defn, #process_defs, #process_gasgn, #process_hash, #process_hash_merge, #process_hash_merge!, #process_helper_method, #process_iasgn, #process_if, #process_if_branch, #process_iter, #process_lasgn, #process_masgn, #process_op_asgn1, #process_op_asgn2, #process_or_simple_operation, #process_or_target, #process_safely, #process_scope, #process_svalue, #raise?, #replace, #same_value?, #self_assign?, #self_assign_target?, #self_assign_var?, #set_value, #simple_when?, #too_deep?, #top_target, #value_from_case, #value_from_if

Methods included from CallConversionHelper

#all_literals?, #join_arrays, #join_strings, #math_op, #process_array_access, #process_hash_access

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Methods included from ProcessorHelper

#current_file, #process_all, #process_all!, #process_call_args, #process_call_defn?, #process_class, #process_module

Methods inherited from SexpProcessor

#in_context, #initialize, #process, processors, #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


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