Short-circuit build coverage extraction for empty regexes

This commit is contained in:
Nick Thomas 2017-07-21 13:04:18 +01:00
parent 754d8caeef
commit 4bda5b502d
4 changed files with 32 additions and 5 deletions

View File

@ -67,7 +67,7 @@ module Gitlab
def extract_coverage(regex) def extract_coverage(regex)
return unless valid? return unless valid?
return unless regex return unless regex.present?
regex = Gitlab::UntrustedRegexp.new(regex) regex = Gitlab::UntrustedRegexp.new(regex)

View File

@ -39,7 +39,12 @@ module Gitlab
groups[1..-1] groups[1..-1]
end 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? break unless text.present?
end end

View File

@ -307,5 +307,27 @@ describe Gitlab::Ci::Trace::Stream do
it { is_expected.to eq('65') } it { is_expected.to eq('65') }
end 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
end end

View File

@ -55,7 +55,7 @@ describe Gitlab::UntrustedRegexp do
let(:text) { 'foo' } let(:text) { 'foo' }
it 'returns an array of empty matches' do it 'returns an array of empty matches' do
is_expected.to eq(['', '', '']) is_expected.to eq([''])
end end
end end
@ -63,8 +63,8 @@ describe Gitlab::UntrustedRegexp do
let(:regexp) { '()' } let(:regexp) { '()' }
let(:text) { 'foo' } let(:text) { 'foo' }
it 'returns arrays of empty matches in an array' do it 'returns an array of empty matches in an array' do
is_expected.to eq([[''], [''], ['']]) is_expected.to eq([['']])
end end
end end