Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-04-03 10:06:50 +0300
committerPatrick Bajao <ebajao@gitlab.com>2019-04-03 10:31:56 +0300
commitac841c37cb667bee637b53d552ce1e71984d7e0a (patch)
treea82d88ae4b1db8ecbe36b433f7227376d0e8954b /lib/gitlab/untrusted_regexp.rb
parente01d3517d5f6cc789ae8a42691440c53e8e4c28f (diff)
Bring back Gitlab::UntrustedRegexp.with_fallback
It's still being called in PushRule model. Also still present in 11-9-stable-ee branch.
Diffstat (limited to 'lib/gitlab/untrusted_regexp.rb')
-rw-r--r--lib/gitlab/untrusted_regexp.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/untrusted_regexp.rb b/lib/gitlab/untrusted_regexp.rb
index 14126b6ec06..c237f4a7404 100644
--- a/lib/gitlab/untrusted_regexp.rb
+++ b/lib/gitlab/untrusted_regexp.rb
@@ -47,6 +47,19 @@ module Gitlab
self.source == other.source
end
+ # Handles regular expressions with the preferred RE2 library where possible
+ # via UntustedRegex. Falls back to Ruby's built-in regular expression library
+ # when the syntax would be invalid in RE2.
+ #
+ # One difference between these is `(?m)` multi-line mode. Ruby regex enables
+ # this by default, but also handles `^` and `$` differently.
+ # See: https://www.regular-expressions.info/modifiers.html
+ def self.with_fallback(pattern, multiline: false)
+ UntrustedRegexp.new(pattern, multiline: multiline)
+ rescue RegexpError
+ Regexp.new(pattern)
+ end
+
private
attr_reader :regexp