Commit d9ef69a9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'ee-10864-fix-undefined-with-fallback' into 'master'

Bring back Gitlab::UntrustedRegexp.with_fallback

Closes #10864

See merge request gitlab-org/gitlab-ee!10563
parents 7a3c88f1 697b5449
...@@ -47,6 +47,19 @@ module Gitlab ...@@ -47,6 +47,19 @@ module Gitlab
self.source == other.source self.source == other.source
end 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 private
attr_reader :regexp attr_reader :regexp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment