diff --git a/lib/gitlab/conflict/parser.rb b/lib/gitlab/conflict/parser.rb index 8ab7b6499aa..9f27cba353a 100644 --- a/lib/gitlab/conflict/parser.rb +++ b/lib/gitlab/conflict/parser.rb @@ -10,8 +10,12 @@ module Gitlab class MissingEndDelimiter < ParserError end + class UnmergeableFile < ParserError + end + def parse(text, our_path:, their_path:, parent: nil) - return [] if text.blank? + raise UnmergeableFile if text.blank? # Typically a binary file + raise UnmergeableFile if text.length > 102400 line_obj_index = 0 line_old = 1 diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb index 1eda14f3e26..65a828accde 100644 --- a/spec/lib/gitlab/conflict/parser_spec.rb +++ b/spec/lib/gitlab/conflict/parser_spec.rb @@ -4,6 +4,10 @@ describe Gitlab::Conflict::Parser, lib: true do let(:parser) { Gitlab::Conflict::Parser.new } describe '#parse' do + def parse_text(text) + parser.parse(text, our_path: 'README.md', their_path: 'README.md') + end + context 'when the file has valid conflicts' do let(:text) do <