summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Nowak <code@dawg.eu>2017-12-06 19:10:53 +0100
committerMartin Nowak <code@dawg.eu>2017-12-07 20:19:37 +0100
commitb7a5125f02865637ffbd4d7f8a623c994b861f0e (patch)
treebaba27d1d0e839931f3b995fd6acd2dafe7c4f50
parentf1a98477014ceee1738a6994da9fd17dd4ccea00 (diff)
downloadgitlab-ce-b7a5125f02865637ffbd4d7f8a623c994b861f0e.tar.gz
fix #39233 - 500 in merge request
- handle unchanged empty lines in inline diff
-rw-r--r--changelogs/unreleased/15774-fix-39233-500-in-merge-request.yml5
-rw-r--r--lib/gitlab/diff/inline_diff.rb2
-rw-r--r--spec/lib/gitlab/diff/inline_diff_spec.rb4
3 files changed, 10 insertions, 1 deletions
diff --git a/changelogs/unreleased/15774-fix-39233-500-in-merge-request.yml b/changelogs/unreleased/15774-fix-39233-500-in-merge-request.yml
new file mode 100644
index 00000000000..1179b3f20e6
--- /dev/null
+++ b/changelogs/unreleased/15774-fix-39233-500-in-merge-request.yml
@@ -0,0 +1,5 @@
+---
+title: 'fix #39233 - 500 in merge request'
+merge_request: 15774
+author: Martin Nowak
+type: fixed
diff --git a/lib/gitlab/diff/inline_diff.rb b/lib/gitlab/diff/inline_diff.rb
index 2d7b57120a6..54783a07919 100644
--- a/lib/gitlab/diff/inline_diff.rb
+++ b/lib/gitlab/diff/inline_diff.rb
@@ -70,7 +70,7 @@ module Gitlab
def find_changed_line_pairs(lines)
# Prefixes of all diff lines, indicating their types
# For example: `" - + -+ ---+++ --+ -++"`
- line_prefixes = lines.each_with_object("") { |line, s| s << line[0] }.gsub(/[^ +-]/, ' ')
+ line_prefixes = lines.each_with_object("") { |line, s| s << (line[0] || ' ') }.gsub(/[^ +-]/, ' ')
changed_line_pairs = []
line_prefixes.scan(LINE_PAIRS_PATTERN) do
diff --git a/spec/lib/gitlab/diff/inline_diff_spec.rb b/spec/lib/gitlab/diff/inline_diff_spec.rb
index 15451c2cf99..0a41362f606 100644
--- a/spec/lib/gitlab/diff/inline_diff_spec.rb
+++ b/spec/lib/gitlab/diff/inline_diff_spec.rb
@@ -31,6 +31,10 @@ describe Gitlab::Diff::InlineDiff do
expect(subject[7]).to eq([17..17])
expect(subject[8]).to be_nil
end
+
+ it 'can handle unchanged empty lines' do
+ expect { described_class.for_lines(['- bar', '+ baz', '']) }.not_to raise_error
+ end
end
describe "#inline_diffs" do