Commit 4bda5b50 authored by Nick Thomas's avatar Nick Thomas
Browse files

Short-circuit build coverage extraction for empty regexes

parent f4db33dd6bf8
......@@ -67,7 +67,7 @@ def html(last_lines: nil)
def extract_coverage(regex)
return unless valid?
return unless regex
return unless regex.present?
regex = Gitlab::UntrustedRegexp.new(regex)
......
......@@ -39,7 +39,12 @@ def scan(text)
groups[1..-1]
end
text.slice!(0, match.end(0) || 1)
matchsize = match.end(0)
# No further matches
break unless matchsize.present?
text.slice!(0, matchsize)
break unless text.present?
end
......
......@@ -307,5 +307,27 @@
it { is_expected.to eq('65') }
end
context 'empty regex' do
let(:data) { 'foo' }
let(:regex) { '' }
it 'skips processing' do
expect(stream).not_to receive(:read)
is_expected.to be_nil
end
end
context 'nil regex' do
let(:data) { 'foo' }
let(:regex) { nil }
it 'skips processing' do
expect(stream).not_to receive(:read)
is_expected.to be_nil
end
end
end
end
......@@ -55,7 +55,7 @@
let(:text) { 'foo' }
it 'returns an array of empty matches' do
is_expected.to eq(['', '', ''])
is_expected.to eq([''])
end
end
......@@ -63,8 +63,8 @@
let(:regexp) { '()' }
let(:text) { 'foo' }
it 'returns arrays of empty matches in an array' do
is_expected.to eq([[''], [''], ['']])
it 'returns an array of empty matches in an array' do
is_expected.to eq([['']])
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment