summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-09-17 16:11:12 +0100
committerNick Thomas <nick@gitlab.com>2018-09-17 19:34:40 +0100
commitb73f3ce58fa6bf0e75ae7f348000b7bce53da9b1 (patch)
treed56a14691f443096076ef0264ea0994ef67a8780 /app/validators
parent50cb63533ff4d90ae317b20157c3fd824783fd61 (diff)
downloadgitlab-ce-b73f3ce58fa6bf0e75ae7f348000b7bce53da9b1.tar.gz
Allow UrlValidator to work with attr_encrypted
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/url_validator.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/validators/url_validator.rb b/app/validators/url_validator.rb
index faaf1283078..216acf79cbd 100644
--- a/app/validators/url_validator.rb
+++ b/app/validators/url_validator.rb
@@ -41,12 +41,13 @@ class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
@record = record
- if value.present?
- value.strip!
- else
+ unless value.present?
record.errors.add(attribute, 'must be a valid URL')
+ return
end
+ value = strip_value!(record, attribute, value)
+
Gitlab::UrlBlocker.validate!(value, blocker_args)
rescue Gitlab::UrlBlocker::BlockedUrlError => e
record.errors.add(attribute, "is blocked: #{e.message}")
@@ -54,6 +55,13 @@ class UrlValidator < ActiveModel::EachValidator
private
+ def strip_value!(record, attribute, value)
+ new_value = value.strip
+ return value if new_value == value
+
+ record.public_send("#{attribute}=", new_value) # rubocop:disable GitlabSecurity/PublicSend
+ end
+
def default_options
# By default the validator doesn't block any url based on the ip address
{