Class Brakeman::AliasProcessor
In: lib/brakeman/processors/alias_processor.rb
Parent: Brakeman::SexpProcessor

Returns an s-expression with aliases replaced with their value. This does not preserve semantics (due to side effects, etc.), but it makes processing easier when searching for various things.

Methods

Included Modules

Brakeman::ProcessorHelper Brakeman::SafeCallHelper Brakeman::Util Brakeman::CallConversionHelper

Constants

ARRAY_CONST = s(:const, :Array)
HASH_CONST = s(:const, :Hash)
RAILS_TEST = s(:call, s(:call, s(:const, :Rails), :env), :test?)

Attributes

result  [R] 
tracker  [R] 

Public Class methods

Returns a new AliasProcessor with an empty environment.

The recommended usage is:

 AliasProcessor.new.process_safely src

Public Instance methods

Check if exp is a call to Array#include? on an array literal that contains all literal values. For example:

   [1, 2, "a"].include? x

Change x.send(:y, 1) to x.y(1)

Finds the inner most call target which is not the target of a call to <<

Handles x = y = z = 1

Returns a new SexpProcessor::Environment containing only instance variables. This is useful, for example, when processing views.

Painful conversion of Array#join into string interpolation

‘Attribute’ assignment

 x.y = 1

or

 x[:y] = 1

Start new scope for block.

Process a method call.

Constant assignments like

 BIG_CONSTANT = 234810983

Class variable assignment

 @@x = 1

Process a Sexp. If the Sexp has a value associated with it in the environment, that value will be returned.

Process a method definition.

Process a method definition on self.

Global assignment

 $x = 1

Return a new hash Sexp with the given values merged into it.

args should be a hash Sexp as well.

Merge values into hash when processing

 h.merge! :something => "value"

Instance variable assignment

 @x = 1

Sets @inside_if = true

Local assignment

 x = 1

Multiple/parallel assignment:

x, y = z, w

Assignments like this

 x[:y] ||= 1

Assignments like this

 x.y ||= 1

If possible, distribute operation over both sides of an or. For example,

    (1 or 2) * 5

Becomes

    (5 or 10)

Only works for strings and numbers right now.

This method processes the given Sexp, but copies it first so the original argument will not be modified.

set_env should be an instance of SexpProcessor::Environment. If provided, it will be used as the starting environment.

This method returns a new Sexp with variables replaced with their values, where possible.

Process a new scope.

This is the right hand side value of a multiple assignment, like `x = y, z`

Return true if lhs == rhs or lhs is an or expression and rhs is one of its values

Return true for x = x.blah

Return true if for x += blah or @x += blah

Set variable to given value. Creates "branched" versions of values when appropriate. Avoids creating multiple branched versions inside same if branch.

Returns last non-nil target in a call chain

[Validate]