summaryrefslogtreecommitdiff
path: root/lib/gitlab/untrusted_regexp.rb
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-03-30 20:51:15 +0000
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-03-30 20:51:15 +0000
commitf4653343ad8475d1d72a55de4face443cc7f66c2 (patch)
treec9c9ebb914be91d9c5996f708721110276a38be1 /lib/gitlab/untrusted_regexp.rb
parent096459e2c2c8e3c17eb6e677091990adffe9af7d (diff)
parenta2b7634113a2b2f3b9aad86b1a98c52c380e5e76 (diff)
downloadgitlab-ce-f4653343ad8475d1d72a55de4face443cc7f66c2.tar.gz
Merge remote-tracking branch 'dev/15-10-stable' into 15-10-stable
Diffstat (limited to 'lib/gitlab/untrusted_regexp.rb')
-rw-r--r--lib/gitlab/untrusted_regexp.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/gitlab/untrusted_regexp.rb b/lib/gitlab/untrusted_regexp.rb
index 96e74f00c78..7c7bda3a8f9 100644
--- a/lib/gitlab/untrusted_regexp.rb
+++ b/lib/gitlab/untrusted_regexp.rb
@@ -47,6 +47,17 @@ module Gitlab
RE2.Replace(text, regexp, rewrite)
end
+ # #scan returns an array of the groups captured, rather than MatchData.
+ # Use this to give the capture group name and grab the proper value
+ def extract_named_group(name, match)
+ return unless match
+
+ match_position = regexp.named_capturing_groups[name.to_s]
+ raise RegexpError, "Invalid named capture group: #{name}" unless match_position
+
+ match[match_position - 1]
+ end
+
def ==(other)
self.source == other.source
end