From cc26ebdc230a8acc7a4c758e9f8948f86d0ca12d Mon Sep 17 00:00:00 2001 From: Mike Poage Date: Tue, 15 Nov 2022 11:51:03 -0500 Subject: [PATCH 1/2] use Warning#relative_path for location path when reporting in codeclimate format * Since Warning#file could return a reference to the abolute path, and codeclimate does not support reporting issues in that format, we want to always ensure that the location of any issue is being reported with a relative location. --- lib/brakeman/report/report_codeclimate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/brakeman/report/report_codeclimate.rb b/lib/brakeman/report/report_codeclimate.rb index 6c1d6f9278..2cfb0fcd38 100644 --- a/lib/brakeman/report/report_codeclimate.rb +++ b/lib/brakeman/report/report_codeclimate.rb @@ -73,7 +73,7 @@ def file_path(warning) if tracker.options[:path_prefix] (Pathname.new(tracker.options[:path_prefix]) + Pathname.new(warning.file.relative)).to_s else - warning.file + warning.relative_path end end end From fa96a9775574d3dd579e763eaaddad9c43fe33d8 Mon Sep 17 00:00:00 2001 From: Mike Poage Date: Tue, 15 Nov 2022 13:59:46 -0500 Subject: [PATCH 2/2] add test to ensure no absolute paths appear in codeclimate output --- test/tests/report_generation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tests/report_generation.rb b/test/tests/report_generation.rb index 402701d24c..3aff3dfb6e 100644 --- a/test/tests/report_generation.rb +++ b/test/tests/report_generation.rb @@ -37,6 +37,7 @@ def test_codeclimate_sanity report = @@report.to_codeclimate assert report.is_a? String + refute report.include? Dir.pwd # Ensure output does not include absolute paths end def test_csv_sanity