diff options
author | Valery Sizov <valery@gitlab.com> | 2017-10-12 18:59:02 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2017-10-15 17:00:36 +0300 |
commit | d09895a0de015073301296597085d8c376870513 (patch) | |
tree | 31d70b0c589c60e5455b55502f149207ed049a40 | |
parent | 1e4b75ba40570a3e96e1999e375a120c4ba8b346 (diff) | |
download | gitlab-ce-d09895a0de015073301296597085d8c376870513.tar.gz |
Fix diff parser so it tolerates to diff special markers in the content
-rw-r--r-- | lib/gitlab/diff/parser.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/parser_spec.rb | 17 |
2 files changed, 20 insertions, 1 deletions
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 |