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_DEV, AliasProcessor::RAILS_TEST, AliasProcessor::STRING_NEW, AliasProcessor::TEMP_FILE_CLASS

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, Util::SIMPLE_LITERALS

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

#all_literals_when?, #array_detect_all_literals?, #array_include_all_literals?, #assign_args, #collapse_send_call, #duplicate?, #early_return?, #equality_check?, #find_method, #find_push_target, #get_call_value, #get_rhs, #hash_include_all_literals?, #hash_or_array_include_all_literals?, #in_array_all_literals?, #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_branch_with_value, #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?, #splat_array?, #temp_file_new, #temp_file_open?, #too_deep?, #top_target, #value_from_case, #value_from_if

Methods included from CallConversionHelper

#hash_values_at, #join_arrays, #join_strings, #math_op, #process_array_access, #process_hash_access

Methods included from Util

#all_literals?, #array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #hash_values, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #recurse_check?, #regexp?, #remove_kwsplat, #request_headers?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #simple_literal?, #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