diff --git a/lib/brakeman.rb b/lib/brakeman.rb index b2edc4bb0d..fc91f3b31f 100644 --- a/lib/brakeman.rb +++ b/lib/brakeman.rb @@ -556,7 +556,7 @@ def self.filter_warnings tracker, options if options[:interactive_ignore] require 'brakeman/report/ignore/interactive' - config = InteractiveIgnorer.new(file, tracker.warnings).start + config = InteractiveIgnorer.new(app_tree, file, tracker.warnings).start else notify "[Notice] Using '#{file}' to filter warnings" config = IgnoreConfig.new(file, tracker.warnings) diff --git a/lib/brakeman/file_path.rb b/lib/brakeman/file_path.rb index 05a6a318cb..a4cedc2cb9 100644 --- a/lib/brakeman/file_path.rb +++ b/lib/brakeman/file_path.rb @@ -50,6 +50,10 @@ def exists? File.exist? self.absolute end + def empty? + self.relative.to_s.empty? + end + # Compare FilePaths. Raises an ArgumentError unless both objects are FilePaths. def <=> rhs raise ArgumentError unless rhs.is_a? Brakeman::FilePath diff --git a/lib/brakeman/report/ignore/interactive.rb b/lib/brakeman/report/ignore/interactive.rb index 81ce04a1dc..0e6799d6f8 100644 --- a/lib/brakeman/report/ignore/interactive.rb +++ b/lib/brakeman/report/ignore/interactive.rb @@ -2,7 +2,7 @@ module Brakeman class InteractiveIgnorer - def initialize file, warnings + def initialize app_tree, file, warnings @ignore_config = Brakeman::IgnoreConfig.new(file, warnings) @new_warnings = warnings @skip_ignored = false @@ -10,6 +10,7 @@ def initialize file, warnings @ignore_rest = false @quit = false @restart = false + @app_tree = app_tree end def start @@ -35,15 +36,17 @@ def start def file_menu loop do - @ignore_config.file = HighLine.new.ask "Input file: " do |q| + input_file = HighLine.new.ask "Input file: " do |q| if @ignore_config.file and not @ignore_config.file.empty? - q.default = @ignore_config.file + q.default = @ignore_config.file.relative else q.default = "config/brakeman.ignore" end end - if File.exist? @ignore_config.file + @ignore_config.file = Brakeman::FilePath.from_app_tree(@app_tree, input_file) + + if @ignore_config.file && @ignore_config.file.exists? @ignore_config.read_from_file return else @@ -168,14 +171,16 @@ def final_menu end def save - @ignore_config.file = HighLine.new.ask "Output file: " do |q| + output_file = HighLine.new.ask "Output file: " do |q| if @ignore_config.file and not @ignore_config.file.empty? - q.default = @ignore_config.file + q.default = @ignore_config.file.relative else q.default = "config/brakeman.ignore" end end + @ignore_config.file = Brakeman::FilePath.from_app_tree(@app_tree, output_file) + @ignore_config.save_with_old end diff --git a/test/tests/file_path.rb b/test/tests/file_path.rb index 80cfbdce9a..6335202b9b 100644 --- a/test/tests/file_path.rb +++ b/test/tests/file_path.rb @@ -43,6 +43,17 @@ def test_file_path_to_str assert_equal "/tmp/blah/thing.rb", "#{fp}" end + def test_file_path_empty? + at = Brakeman::AppTree.new("/tmp/blah") + fp1 = Brakeman::FilePath.from_app_tree at, "/tmp/blah/thing.rb" + fp2 = Brakeman::FilePath.from_app_tree at, "/tmp/blah/thing/" + fp3 = Brakeman::FilePath.from_app_tree at, "" + + refute fp1.empty? + refute fp2.empty? + assert fp3.empty? + end + def test_file_path_equality at = Brakeman::AppTree.new("/tmp/blah") fp1 = Brakeman::FilePath.from_app_tree at, "/tmp/blah/thing.rb"