summaryrefslogtreecommitdiff
path: root/lib/gitlab/untrusted_regexp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/untrusted_regexp.rb')
-rw-r--r--lib/gitlab/untrusted_regexp.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/gitlab/untrusted_regexp.rb b/lib/gitlab/untrusted_regexp.rb
index 70d1a7c6535..dc2d91dfa23 100644
--- a/lib/gitlab/untrusted_regexp.rb
+++ b/lib/gitlab/untrusted_regexp.rb
@@ -55,7 +55,7 @@ module Gitlab
end
def self.valid?(pattern)
- self.fabricate(pattern)
+ !!self.fabricate(pattern)
rescue RegexpError
false
end
@@ -63,16 +63,13 @@ module Gitlab
def self.fabricate(pattern)
matches = pattern.match(%r{^/(?<regexp>.+)/(?<flags>[ismU]*)$})
- if matches
- expression = matches[:regexp]
- flags = matches[:flags]
+ raise RegexpError, 'Invalid regular expression!' if matches.nil?
- expression.prepend("(?#{flags})") if flags.present?
+ expression = matches[:regexp]
+ flags = matches[:flags]
+ expression.prepend("(?#{flags})") if flags.present?
- self.new(expression, multiline: false)
- else
- self.new(pattern, multiline: false)
- end
+ self.new(expression, multiline: false)
end
private