diff --git a/lib/brakeman/report.rb b/lib/brakeman/report.rb index e0ae00930cb86103067ddd2d5fcc1fa6f58ffd7c..4c7041a134d63e2467b7b047e5796bab8236de36 100644 --- a/lib/brakeman/report.rb +++ b/lib/brakeman/report.rb @@ -1,5 +1,6 @@ require 'cgi' require 'set' +require 'pathname' require 'brakeman/processors/output_processor' require 'brakeman/util' require 'terminal-table' @@ -651,16 +652,13 @@ class Brakeman::Report errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }} app_path = tracker.options[:app_path] - if tracker.options[:relative_path] - warnings = all_warnings.map { |w| - hash = w.to_hash - if file = hash[:file] - hash.update :file => file.sub( /^#{app_path}/,'.' ) - end - }.sort_by{|w| w[:file]} - else - warnings = all_warnings.map { |w| w.to_hash }.sort_by{|w| w[:file]} - end + + warnings = all_warnings.map do |w| + hash = w.to_hash + hash[:file] = warning_file w + hash + end.sort_by { |w| w[:file] } + scan_info = { :app_path => File.expand_path(tracker.options[:app_path]), :rails_version => rails_version, @@ -690,6 +688,16 @@ class Brakeman::Report Set.new(tracker.templates.map {|k,v| v[:name].to_s[/[^.]+/]}).length 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 def load_and_render_erb file, bind