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