Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use multi_json instead of json gem

closes #164
  • Loading branch information...
commit ebba5cd2db83433b2c9771c2450e764d01d265d9 1 parent 4734298
@presidentbeef presidentbeef authored
View
3  bin/brakeman
@@ -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
View
2  brakeman.gemspec
@@ -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
View
9 lib/brakeman.rb
@@ -316,19 +316,20 @@ def self.debug message
# 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
View
7 lib/brakeman/report.rb
@@ -6,6 +6,7 @@
require 'terminal-table'
require 'highline/system_extensions'
require "csv"
+require 'multi_json'
require 'brakeman/version'
if CSV.const_defined? :Reader
@@ -647,8 +648,6 @@ def to_test
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 @@ def to_json
:brakeman_version => Brakeman::Version
}
- JSON.pretty_generate({
+ MultiJson.dump({
:scan_info => scan_info,
:warnings => warnings,
:errors => errors
- })
+ }, :pretty => true)
end
def all_warnings
View
6 lib/brakeman/warning.rb
@@ -1,3 +1,5 @@
+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 @@ def to_hash
end
def to_json
- require 'json'
-
- JSON.dump self.to_hash
+ MultiJson.dump self.to_hash
end
end
View
2  test/tests/test_json_compare.rb
@@ -6,7 +6,7 @@ def setup
@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
Please sign in to comment.
Something went wrong with that request. Please try again.