Short-circuit build coverage extraction for empty regexes
This commit is contained in:
parent
754d8caeef
commit
4bda5b502d
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue