diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-18 11:14:10 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-18 11:14:10 +0300 |
commit | af9b0bfbae84a402e5c706ac29772b0d70dfa156 (patch) | |
tree | cba1e625db3ca4f6e74c2d96ee04f2c24fabc994 /lib/gitlab | |
parent | 61d55b56ab4ee7d11484eeea6fabb2412af6578f (diff) |
Simplify untrusted regexp factory method
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/untrusted_regexp.rb | 15 |
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 |