diff options
author | Sean McGivern <sean@gitlab.com> | 2018-01-30 15:17:44 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-01-30 15:17:44 +0000 |
commit | 382421a9bed1ef0fd1e97f6dcec8a104342ae1d8 (patch) | |
tree | 2be2a81e676fadc4d12e7e2a2e76e7433759da93 | |
parent | e74e6fcb5eecb7841a412cb0d3e9627556d83eaf (diff) | |
download | gitlab-ce-382421a9bed1ef0fd1e97f6dcec8a104342ae1d8.tar.gz |
Fix truncated_diff_lines for legacy notes without a line42160-error-500-loading-merge-request-undefined-method-index-for-nil-nilclass
It appears that some legacy diff notes on GitLab.com have invalid line codes,
which means truncated_diff_lines won't work. This is just a band-aid solution,
as neither the diff nor the discussion will display correctly for these notes,
but they won't cause a 500 error.
3 files changed, 17 insertions, 0 deletions
diff --git a/app/models/concerns/discussion_on_diff.rb b/app/models/concerns/discussion_on_diff.rb index db9770fabf4..8b3c55387b3 100644 --- a/app/models/concerns/discussion_on_diff.rb +++ b/app/models/concerns/discussion_on_diff.rb @@ -37,6 +37,8 @@ module DiscussionOnDiff # Returns an array of at most 16 highlighted lines above a diff note def truncated_diff_lines(highlight: true) + return [] if diff_line.nil? && first_note.is_a?(LegacyDiffNote) + lines = highlight ? highlighted_diff_lines : diff_lines initial_line_index = [diff_line.index - NUMBER_OF_TRUNCATED_DIFF_LINES + 1, 0].max diff --git a/changelogs/unreleased/42160-error-500-loading-merge-request-undefined-method-index-for-nil-nilclass.yml b/changelogs/unreleased/42160-error-500-loading-merge-request-undefined-method-index-for-nil-nilclass.yml new file mode 100644 index 00000000000..64340ab08cd --- /dev/null +++ b/changelogs/unreleased/42160-error-500-loading-merge-request-undefined-method-index-for-nil-nilclass.yml @@ -0,0 +1,5 @@ +--- +title: Fix 500 error when loading a merge request with an invalid comment +merge_request: 16795 +author: +type: fixed diff --git a/spec/models/concerns/discussion_on_diff_spec.rb b/spec/models/concerns/discussion_on_diff_spec.rb index 2322eb206fb..30572ce9332 100644 --- a/spec/models/concerns/discussion_on_diff_spec.rb +++ b/spec/models/concerns/discussion_on_diff_spec.rb @@ -20,6 +20,16 @@ describe DiscussionOnDiff do expect(truncated_lines).not_to include(be_meta) end end + + context "when the diff line does not exist on a legacy diff note" do + it "returns an empty array" do + legacy_note = LegacyDiffNote.new + + allow(subject).to receive(:first_note).and_return(legacy_note) + + expect(truncated_lines).to eq([]) + end + end end describe '#line_code_in_diffs' do |