diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-07-31 09:54:03 +0300 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-07-31 09:54:03 +0300 |
commit | 5c7f2853dc5a8eca874108a0217a115090f29e9b (patch) | |
tree | 15e22a546814fa495fbb00ce1fdfbf2efa97a1d2 /app/models | |
parent | 67ffe3ced0a704d78f528e5dc8ea4243e5e4a47f (diff) |
Allow blank but not nil in validations
- The most common use case for qualified_domain_validator currently is
to allow blank ([]) but not allow nil. Modify the
qualified_domain_validator to support this use case.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 6 | ||||
-rw-r--r-- | app/models/application_setting_implementation.rb | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index a769a8f07fd..9dbcef8abaa 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -42,9 +42,9 @@ class ApplicationSetting < ApplicationRecord validates :uuid, presence: true validates :outbound_local_requests_whitelist, - length: { maximum: 1_000, message: N_('is too long (maximum is 1000 entries)') } - - validates :outbound_local_requests_whitelist, qualified_domain_array: true, allow_blank: true + length: { maximum: 1_000, message: N_('is too long (maximum is 1000 entries)') }, + allow_nil: false, + qualified_domain_array: true validates :session_expire_delay, presence: true, diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index 1e612bd0e78..6efd07a6008 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -163,6 +163,8 @@ module ApplicationSettingImplementation def outbound_local_requests_whitelist_arrays strong_memoize(:outbound_local_requests_whitelist_arrays) do + next [[], []] unless self.outbound_local_requests_whitelist + ip_whitelist = [] domain_whitelist = [] @@ -284,6 +286,8 @@ module ApplicationSettingImplementation end def domain_strings_to_array(values) + return [] unless values + values .split(DOMAIN_LIST_SEPARATOR) .reject(&:empty?) |