Commit 3f02ca1e authored by Robert May's avatar Robert May Committed by Dmytro Zaporozhets

Ensure broken diff notes don't error out

This is to prevent many issues when rendering notes that are
corrupted in some way. There seem to be multiple bugs that
allow this to happen, and the result is that it fails to
render the entire block of notes.
parent 91fee199
......@@ -40,7 +40,7 @@ module DiscussionOnDiff
# Returns an array of at most 16 highlighted lines above a diff note
def truncated_diff_lines(highlight: true, diff_limit: nil)
return [] unless on_text?
return [] if diff_line.nil? && first_note.is_a?(LegacyDiffNote)
return [] if diff_line.nil?
diff_limit = [diff_limit, NUMBER_OF_TRUNCATED_DIFF_LINES].compact.min
lines = highlight ? highlighted_diff_lines : diff_lines
......
---
title: Fix Merge Request comments when some notes are corrupt
merge_request: 23786
author:
type: fixed
......@@ -59,6 +59,18 @@ describe DiscussionOnDiff do
end
end
context "when the diff line does not exist on a corrupt diff note" do
subject { create(:diff_note_on_merge_request, line_number: 18).to_discussion }
before do
allow(subject).to receive(:diff_line) { nil }
end
it "returns an empty array" do
expect(truncated_lines).to eq([])
end
end
context 'when the discussion is on an image' do
subject { create(:image_diff_note_on_merge_request).to_discussion }
......
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