diff options
author | Nick Thomas <nick@gitlab.com> | 2017-07-24 12:53:57 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-07-24 13:03:37 +0300 |
commit | 61f948baed18788c2bb34dd6d5da452a19f58e52 (patch) | |
tree | d3a8017f735771fab7c16240929da22870e3754f /lib/gitlab/untrusted_regexp.rb | |
parent | 883488e0b2adda7dad93334f17f3895f05a7c587 (diff) |
Upgrade the re2 gem to 1.1.0
Diffstat (limited to 'lib/gitlab/untrusted_regexp.rb')
-rw-r--r-- | lib/gitlab/untrusted_regexp.rb | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/lib/gitlab/untrusted_regexp.rb b/lib/gitlab/untrusted_regexp.rb index 187a9e1145f..7ce2e9d636e 100644 --- a/lib/gitlab/untrusted_regexp.rb +++ b/lib/gitlab/untrusted_regexp.rb @@ -22,33 +22,9 @@ module Gitlab end def scan(text) - text = text.dup # modified in-place - results = [] - - 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 + matches = scan_regexp.scan(text).to_a + matches.map!(&:first) if regexp.number_of_capturing_groups.zero? + matches end def replace(text, rewrite) |