Fix diff parser so it tolerates to diff special markers in the content
This commit is contained in:
parent
1e4b75ba40
commit
d09895a0de
|
@ -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")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue