Commit 95ea0ba4 authored by rossfuhrman's avatar rossfuhrman Committed by Douglas Barbosa Alexandre

Guard against nil file key

Not all scanners populate the file key in the location hash, so we need
to guard against that.
parent 65d6b7e3
...@@ -6,7 +6,7 @@ module Vulnerabilities ...@@ -6,7 +6,7 @@ module Vulnerabilities
def blob_path def blob_path
return '' unless respond_to?(:sha) return '' unless respond_to?(:sha)
return '' unless location.present? return '' unless location.present? && location['file'].present?
add_line_numbers(location['start_line'], location['end_line']) add_line_numbers(location['start_line'], location['end_line'])
end end
......
...@@ -46,6 +46,15 @@ describe Vulnerabilities::OccurrencePresenter do ...@@ -46,6 +46,15 @@ describe Vulnerabilities::OccurrencePresenter do
it { is_expected.to end_with('#L1-2') } it { is_expected.to end_with('#L1-2') }
end end
context 'without file' do
before do
allow(presenter).to receive(:location)
.and_return({ 'foo' => 123 })
end
it { is_expected.to be_blank }
end
context 'without location' do context 'without location' do
before do before do
allow(presenter).to receive(:location) allow(presenter).to receive(:location)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment