summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-04-03 15:06:50 +0800
committerPatrick Bajao <ebajao@gitlab.com>2019-04-03 15:31:56 +0800
commitac841c37cb667bee637b53d552ce1e71984d7e0a (patch)
treea82d88ae4b1db8ecbe36b433f7227376d0e8954b
parente01d3517d5f6cc789ae8a42691440c53e8e4c28f (diff)
downloadgitlab-ce-10864-fix-undefined-with-fallback.tar.gz
Bring back Gitlab::UntrustedRegexp.with_fallback10864-fix-undefined-with-fallback
It's still being called in PushRule model. Also still present in 11-9-stable-ee branch.
-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