提交 ebba5cd2 编写于 作者: J Justin Collins

Use multi_json instead of json gem

closes #164
上级 47342987
......@@ -54,7 +54,8 @@ end
if options[:previous_results_json]
vulns = Brakeman.compare options.merge(:quiet => options[:quiet])
puts JSON.pretty_generate(vulns)
puts MultiJson.dump(vulns, :pretty => true)
if options[:exit_on_warn] and (vulns[:new].count + vulns[:fixed].count > 0)
exit Brakeman::Warnings_Found_Exit_Code
end
......
......@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
s.add_dependency "erubis", "~>2.6"
s.add_dependency "haml", "~>3.0"
s.add_dependency "sass", "~>3.0"
s.add_dependency "json_pure"
s.add_dependency "multi_json"
end
......@@ -316,19 +316,20 @@ module Brakeman
# Compare JSON ouptut from a previous scan and return the diff of the two scans
def self.compare options
require 'json'
require 'multi_json'
require 'brakeman/differ'
raise ArgumentError.new("Comparison file doesn't exist") unless File.exists? options[:previous_results_json]
begin
previous_results = JSON.parse(File.read(options[:previous_results_json]), :symbolize_names =>true)[:warnings]
rescue JSON::ParserError
previous_results = MultiJson.load(File.read(options[:previous_results_json]), :symbolize_keys => true)[:warnings]
rescue MultiJson::DecodeError
self.notify "Error parsing comparison file: #{options[:previous_results_json]}"
exit!
end
tracker = run(options)
new_results = JSON.parse(tracker.report.to_json, :symbolize_names =>true)[:warnings]
new_results = MultiJson.load(tracker.report.to_json, :symbolize_keys => true)[:warnings]
Brakeman::Differ.new(new_results, previous_results).diff
end
......
......@@ -6,6 +6,7 @@ require 'brakeman/util'
require 'terminal-table'
require 'highline/system_extensions'
require "csv"
require 'multi_json'
require 'brakeman/version'
if CSV.const_defined? :Reader
......@@ -647,8 +648,6 @@ class Brakeman::Report
end
def to_json
require 'json'
errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }}
app_path = tracker.options[:app_path]
......@@ -672,11 +671,11 @@ class Brakeman::Report
:brakeman_version => Brakeman::Version
}
JSON.pretty_generate({
MultiJson.dump({
:scan_info => scan_info,
:warnings => warnings,
:errors => errors
})
}, :pretty => true)
end
def all_warnings
......
require 'multi_json'
#The Warning class stores information about warnings
class Brakeman::Warning
attr_reader :called_from, :check, :class, :confidence, :controller,
......@@ -177,8 +179,6 @@ class Brakeman::Warning
end
def to_json
require 'json'
JSON.dump self.to_hash
MultiJson.dump self.to_hash
end
end
......@@ -6,7 +6,7 @@ class JSONCompareTests < Test::Unit::TestCase
@json_path = File.join @path, "report.json"
File.delete @json_path if File.exist? @json_path
Brakeman.run :app_path => @path, :output_files => [@json_path]
@report = JSON.parse File.read(@json_path)
@report = MultiJson.load File.read(@json_path)
end
def update_json
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册