提交 369e8ce0 编写于 作者: J Justin Collins

Fix output format detection to be more strict again

and also -f should override detection
上级 6bbe03cd
...@@ -296,7 +296,7 @@ module Brakeman ...@@ -296,7 +296,7 @@ module Brakeman
def self.write_report_to_files tracker, output_files def self.write_report_to_files tracker, output_files
output_files.each_with_index do |output_file, idx| output_files.each_with_index do |output_file, idx|
File.open output_file, "w" do |f| File.open output_file, "w" do |f|
f.write tracker.report.format(output_file) f.write tracker.report.format(tracker.options[:output_formats][idx])
end end
notify "Report saved in '#{output_file}'" notify "Report saved in '#{output_file}'"
end end
......
...@@ -283,23 +283,14 @@ class Brakeman::Report ...@@ -283,23 +283,14 @@ class Brakeman::Report
end end
end end
# format output from filename or format # format output
def format(filename_or_format) def format format
case filename_or_format valid_formats = [:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_test, :to_s]
when /\.html/, :to_html
to_html if valid_formats.include? format
when /\.pdf/, :to_pdf self.send(format)
to_pdf
when /\.csv/, :to_csv
to_csv
when /\.json/, :to_json
to_json
when /\.tabs/, :to_tabs
to_tabs
when :to_test
to_test
else else
to_s raise "Invalid format: #{format}. Should be one of #{valid_formats.inspect}"
end end
end end
......
...@@ -39,4 +39,10 @@ class TestReportGeneration < Test::Unit::TestCase ...@@ -39,4 +39,10 @@ class TestReportGeneration < Test::Unit::TestCase
assert report.is_a? String assert report.is_a? String
end end
def test_bad_format_type
assert_raises RuntimeError do
Report.format(:to_something_else)
end
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册