Commit d60b09d9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'short-circuit-coverage-with-empty-regex' into 'master'

Short-circuit build coverage extraction for empty regexes

See merge request !13015
parents 754d8cae 4bda5b50
No related merge requests found
......@@ -67,7 +67,7 @@ module Gitlab
def extract_coverage(regex)
return unless valid?
return unless regex
return unless regex.present?
regex = Gitlab::UntrustedRegexp.new(regex)
......
......@@ -39,7 +39,12 @@ module Gitlab
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 @@ describe Gitlab::Ci::Trace::Stream do
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 @@ describe Gitlab::UntrustedRegexp do
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 @@ describe Gitlab::UntrustedRegexp do
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