Commit 9439d2a9 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'nicolasdular/regex-validator-to-ce' into 'master'

Use existing regexp validator

See merge request gitlab-org/gitlab!27672
parents 52d8ed21 b2946af5
...@@ -257,7 +257,7 @@ class ApplicationSetting < ApplicationRecord ...@@ -257,7 +257,7 @@ class ApplicationSetting < ApplicationRecord
validates :snippet_size_limit, numericality: { only_integer: true, greater_than: 0 } validates :snippet_size_limit, numericality: { only_integer: true, greater_than: 0 }
validate :email_restrictions_regex_valid? validates :email_restrictions, untrusted_regexp: true
SUPPORTED_KEY_TYPES.each do |type| SUPPORTED_KEY_TYPES.each do |type|
validates :"#{type}_key_restriction", presence: true, key_restriction: { type: type } validates :"#{type}_key_restriction", presence: true, key_restriction: { type: type }
...@@ -411,14 +411,6 @@ class ApplicationSetting < ApplicationRecord ...@@ -411,14 +411,6 @@ class ApplicationSetting < ApplicationRecord
recaptcha_enabled || login_recaptcha_protection_enabled recaptcha_enabled || login_recaptcha_protection_enabled
end end
def email_restrictions_regex_valid?
return if email_restrictions.blank?
Gitlab::UntrustedRegexp.new(email_restrictions)
rescue RegexpError
errors.add(:email_restrictions, _('is not a valid regular expression'))
end
private private
def parsed_grafana_url def parsed_grafana_url
......
...@@ -23939,9 +23939,6 @@ msgstr "" ...@@ -23939,9 +23939,6 @@ msgstr ""
msgid "is not a valid X509 certificate." msgid "is not a valid X509 certificate."
msgstr "" msgstr ""
msgid "is not a valid regular expression"
msgstr ""
msgid "is not allowed for sign-up" msgid "is not allowed for sign-up"
msgstr "" msgstr ""
......
...@@ -715,7 +715,7 @@ describe ApplicationSetting do ...@@ -715,7 +715,7 @@ describe ApplicationSetting do
subject.email_restrictions = '+' subject.email_restrictions = '+'
expect(subject).not_to be_valid expect(subject).not_to be_valid
expect(subject.errors.messages[:email_restrictions].first).to eq(_('is not a valid regular expression')) expect(subject.errors.messages[:email_restrictions].first).to eq(_('not valid RE2 syntax: no argument for repetition operator: +'))
end end
end end
......
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