Skip to content
Snippets Groups Projects
Commit 61f948ba authored by Nick Thomas's avatar Nick Thomas
Browse files

Upgrade the re2 gem to 1.1.0

parent 883488e0
No related branches found
No related tags found
No related merge requests found
Loading
@@ -164,7 +164,7 @@ gem 'rainbow', '~> 2.2'
Loading
@@ -164,7 +164,7 @@ gem 'rainbow', '~> 2.2'
gem 'settingslogic', '~> 2.0.9' gem 'settingslogic', '~> 2.0.9'
   
# Linear-time regex library for untrusted regular expressions # Linear-time regex library for untrusted regular expressions
gem 're2', '~> 1.0.0' gem 're2', '~> 1.1.0'
   
# Misc # Misc
   
Loading
Loading
Loading
@@ -656,7 +656,7 @@ GEM
Loading
@@ -656,7 +656,7 @@ GEM
debugger-ruby_core_source (~> 1.3) debugger-ruby_core_source (~> 1.3)
rdoc (4.2.2) rdoc (4.2.2)
json (~> 1.4) json (~> 1.4)
re2 (1.0.0) re2 (1.1.0)
recaptcha (3.0.0) recaptcha (3.0.0)
json json
recursive-open-struct (1.0.0) recursive-open-struct (1.0.0)
Loading
@@ -1055,7 +1055,7 @@ DEPENDENCIES
Loading
@@ -1055,7 +1055,7 @@ DEPENDENCIES
raindrops (~> 0.18) raindrops (~> 0.18)
rblineprof (~> 0.3.6) rblineprof (~> 0.3.6)
rdoc (~> 4.2) rdoc (~> 4.2)
re2 (~> 1.0.0) re2 (~> 1.1.0)
recaptcha (~> 3.0) recaptcha (~> 3.0)
redcarpet (~> 3.4) redcarpet (~> 3.4)
redis (~> 3.2) redis (~> 3.2)
Loading
Loading
Loading
@@ -22,33 +22,9 @@ module Gitlab
Loading
@@ -22,33 +22,9 @@ module Gitlab
end end
   
def scan(text) def scan(text)
text = text.dup # modified in-place matches = scan_regexp.scan(text).to_a
results = [] matches.map!(&:first) if regexp.number_of_capturing_groups.zero?
matches
loop do
match = scan_regexp.match(text)
break unless match
# Ruby scan returns empty strings, not nil
groups = match.to_a.map(&:to_s)
results <<
if regexp.number_of_capturing_groups.zero?
groups[0]
else
groups[1..-1]
end
matchsize = match.end(0)
# No further matches
break unless matchsize.present?
text.slice!(0, matchsize)
break unless text.present?
end
results
end end
   
def replace(text, rewrite) def replace(text, rewrite)
Loading
Loading
Loading
@@ -308,6 +308,20 @@ describe Gitlab::Ci::Trace::Stream do
Loading
@@ -308,6 +308,20 @@ describe Gitlab::Ci::Trace::Stream do
it { is_expected.to eq('65') } it { is_expected.to eq('65') }
end end
   
context 'long line' do
let(:data) { 'a' * 80000 + '100%' + 'a' * 80000 }
let(:regex) { '\d+\%' }
it { is_expected.to eq('100') }
end
context 'many lines' do
let(:data) { "foo\n" * 80000 + "100%\n" + "foo\n" * 80000 }
let(:regex) { '\d+\%' }
it { is_expected.to eq('100') }
end
context 'empty regex' do context 'empty regex' do
let(:data) { 'foo' } let(:data) { 'foo' }
let(:regex) { '' } let(:regex) { '' }
Loading
Loading
Loading
@@ -54,8 +54,8 @@ describe Gitlab::UntrustedRegexp do
Loading
@@ -54,8 +54,8 @@ describe Gitlab::UntrustedRegexp do
let(:regexp) { '' } let(:regexp) { '' }
let(:text) { 'foo' } let(:text) { 'foo' }
   
it 'returns an array of empty matches' do it 'returns an array of nil matches' do
is_expected.to eq(['']) is_expected.to eq([nil, nil, nil, nil])
end end
end end
   
Loading
@@ -63,8 +63,8 @@ describe Gitlab::UntrustedRegexp do
Loading
@@ -63,8 +63,8 @@ describe Gitlab::UntrustedRegexp do
let(:regexp) { '()' } let(:regexp) { '()' }
let(:text) { 'foo' } let(:text) { 'foo' }
   
it 'returns an array of empty matches in an array' do it 'returns an array of nil matches in an array' do
is_expected.to eq([['']]) is_expected.to eq([[nil], [nil], [nil], [nil]])
end end
end end
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment