提交 925df9cf 编写于 作者: J Justin Collins

Add relative paths for JSON output

上级 ce2ee305
require 'cgi' require 'cgi'
require 'set' require 'set'
require 'pathname'
require 'brakeman/processors/output_processor' require 'brakeman/processors/output_processor'
require 'brakeman/util' require 'brakeman/util'
require 'terminal-table' require 'terminal-table'
...@@ -651,16 +652,13 @@ class Brakeman::Report ...@@ -651,16 +652,13 @@ class Brakeman::Report
errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }} errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }}
app_path = tracker.options[:app_path] app_path = tracker.options[:app_path]
if tracker.options[:relative_path]
warnings = all_warnings.map { |w| warnings = all_warnings.map do |w|
hash = w.to_hash hash = w.to_hash
if file = hash[:file] hash[:file] = warning_file w
hash.update :file => file.sub( /^#{app_path}/,'.' ) hash
end end.sort_by { |w| w[:file] }
}.sort_by{|w| w[:file]}
else
warnings = all_warnings.map { |w| w.to_hash }.sort_by{|w| w[:file]}
end
scan_info = { scan_info = {
:app_path => File.expand_path(tracker.options[:app_path]), :app_path => File.expand_path(tracker.options[:app_path]),
:rails_version => rails_version, :rails_version => rails_version,
...@@ -690,6 +688,16 @@ class Brakeman::Report ...@@ -690,6 +688,16 @@ class Brakeman::Report
Set.new(tracker.templates.map {|k,v| v[:name].to_s[/[^.]+/]}).length Set.new(tracker.templates.map {|k,v| v[:name].to_s[/[^.]+/]}).length
end end
def warning_file warning, relative = false
return nil if warning.file.nil?
if @tracker.options[:relative_paths] or relative
Pathname.new(warning.file).relative_path_from(Pathname.new(tracker.options[:app_path])).to_s
else
warning.file
end
end
private private
def load_and_render_erb file, bind def load_and_render_erb file, bind
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册