Fix diff parser so it tolerates to diff special markers in the content

This commit is contained in:
Valery Sizov 2017-10-12 18:59:02 +03:00
parent 1e4b75ba40
commit d09895a0de
2 changed files with 20 additions and 1 deletions

View File

@ -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")

View File

@ -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