Merge branch '10864-fix-undefined-with-fallback' into 'master'
Backport: Bring back Gitlab::UntrustedRegexp.with_fallback See merge request gitlab-org/gitlab-ce!26901
This commit is contained in:
commit
f4e8f6c89b
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue