Sha256: 9e9a4e2e022bcb962b681aaef9bd11cdfe92c44026ce8b4796856b79336388eb

Contents?: true

Size: 1.29 KB

Versions: 39

Compression:

Stored size: 1.29 KB

Contents

require 'brakeman/processors/lib/basic_processor'

#Processes Gemfile and Gemfile.lock
class Brakeman::GemProcessor < Brakeman::BasicProcessor

  def initialize *args
    super
    @gem_name_version = /^\s*([-_+.A-Za-z0-9]+) \((\w(\.\w+)*)\)/
  end

  def process_gems gem_files
    @gem_files = gem_files
    @gemfile = gem_files[:gemfile][:file]
    process gem_files[:gemfile][:src]

    if gem_files[:gemlock]
      process_gem_lock
    end

    @tracker.config.set_rails_version
  end

  def process_call exp
    if exp.target == nil and exp.method == :gem
      gem_name = exp.first_arg
      return exp unless string? gem_name

      gem_version = exp.second_arg

      version = if string? gem_version
                  gem_version.value
                else
                  nil
                end

      @tracker.config.add_gem gem_name.value, version, @gemfile, exp.line
    end

    exp
  end

  def process_gem_lock
    line_num = 1
    file = @gem_files[:gemlock][:file]
    @gem_files[:gemlock][:src].each_line do |line|
      set_gem_version_and_file line, file, line_num
      line_num += 1
    end
  end

  # Supports .rc2 but not ~>, >=, or <=
  def set_gem_version_and_file line, file, line_num
    if line =~ @gem_name_version
      @tracker.config.add_gem $1, $2, file, line_num
    end
  end
end

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
brakeman-3.4.0 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.4.0 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.4.0 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.5 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.3.5 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.5 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.4 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.3.4 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.4 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.3 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.3.3 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.3 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.2 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.3.2 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.2 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.1 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.1 lib/brakeman/processors/gem_processor.rb
brakeman-lib-3.3.1 lib/brakeman/processors/gem_processor.rb
brakeman-3.3.0 lib/brakeman/processors/gem_processor.rb
brakeman-min-3.3.0 lib/brakeman/processors/gem_processor.rb