Sha256: b113ed587d9338aecd94f035fcb857ff69e52222c2ea6fe3258acb864bfa246c

Contents?: true

Size: 1.46 KB

Versions: 13

Compression:

Stored size: 1.46 KB

Contents

module Brakeman
  ASTFile = Struct.new(:path, :ast)

  # This class handles reading and parsing files.
  class FileParser
    attr_reader :file_list

    def initialize tracker
      @tracker = tracker
      @timeout = @tracker.options[:parser_timeout]
      @app_tree = @tracker.app_tree
      @file_list = {}
    end

    def parse_files list, type
      read_files list, type do |path, contents|
        if ast = parse_ruby(contents, path.relative)
          ASTFile.new(path, ast)
        end
      end
    end

    def read_files list, type
      @file_list[type] ||= []

      list.each do |path|
        file = @app_tree.file_path(path)

        result = yield file, file.read
        if result
          @file_list[type] << result
        end
      end
    end

    def parse_ruby input, path, parser = RubyParser.new
      begin
        Brakeman.debug "Parsing #{path}"
        parser.parse input, path, @timeout
      rescue Racc::ParseError => e
        if parser.class == RubyParser
          return parse_ruby(input, path, RubyParser.latest)
        else
          @tracker.error e, "Could not parse #{path}"
          nil
        end
      rescue Timeout::Error => e
        @tracker.error Exception.new("Parsing #{path} took too long (> #{@timeout} seconds). Try increasing the limit with --parser-timeout"), caller
        nil
      rescue => e
        @tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace
        nil
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/lib/brakeman/file_parser.rb
brakeman-4.5.1 lib/brakeman/file_parser.rb
brakeman-lib-4.5.1 lib/brakeman/file_parser.rb
brakeman-min-4.5.1 lib/brakeman/file_parser.rb