diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-10-16 10:11:55 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-11-06 19:54:54 +0800 |
commit | 2dd66ad34a5b4a2d50da31ae440470ef02d28aaf (patch) | |
tree | a84bf014487bb05668f61481dc1d69129d9d73ab | |
parent | 411cc6e4c59e6f61181d456cec127c344f277a7f (diff) | |
download | gitlab-ce-2dd66ad34a5b4a2d50da31ae440470ef02d28aaf.tar.gz |
Merge branch 'fix_diff_parsing' into 'master'
Fix diff parser so it tolerates to diff special markers in the content
Closes #34431
See merge request gitlab-org/gitlab-ce!14848
-rw-r--r-- | changelogs/unreleased/fix_diff_parsing.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/diff/parser.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/parser_spec.rb | 17 |
3 files changed, 25 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix_diff_parsing.yml b/changelogs/unreleased/fix_diff_parsing.yml new file mode 100644 index 00000000000..7a26b4f9ff5 --- /dev/null +++ b/changelogs/unreleased/fix_diff_parsing.yml @@ -0,0 +1,5 @@ +--- +title: Fix diff parser so it tolerates to diff special markers in the content +merge_request: +author: +type: fixed diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 742f989c50b..7dc9cc7c281 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -17,7 +17,9 @@ module Gitlab # without having to instantiate all the others that come after it. Enumerator.new do |yielder| @lines.each do |line| - next if filename?(line) + # We're expecting a filename parameter only in a meta-part of the diff content + # when type is defined then we're already in a content-part + next if filename?(line) && type.nil? full_line = line.delete("\n") diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb index 8af49ed50ff..80c8c189665 100644 --- a/spec/lib/gitlab/diff/parser_spec.rb +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -143,4 +143,21 @@ eos it { expect(parser.parse([])).to eq([]) } it { expect(parser.parse(nil)).to eq([]) } end + + describe 'tolerates special diff markers in a content' do + it "counts lines correctly" do + diff = <<~END + --- a/test + +++ b/test + @@ -1,2 +1,2 @@ + +ipsum + +++ b + -ipsum + END + + lines = parser.parse(diff.lines).to_a + + expect(lines.size).to eq(3) + end + end end |