summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-06-30 13:17:37 +0200
committerJames Lopez <james@jameslopez.es>2016-06-30 13:17:37 +0200
commit5b893d603dd68f263129523f13e8eb68b67fe790 (patch)
treef17be7ff52f89672f6895c45d0c15e687e50527a /app/validators
parent0ca275748314a27a1f36e12fe1360df11c9be25d (diff)
downloadgitlab-ce-5b893d603dd68f263129523f13e8eb68b67fe790.tar.gz
few changes based on feedback
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/addressable_url_validator.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/app/validators/addressable_url_validator.rb b/app/validators/addressable_url_validator.rb
index 634a15aea01..c97acf7da95 100644
--- a/app/validators/addressable_url_validator.rb
+++ b/app/validators/addressable_url_validator.rb
@@ -18,6 +18,9 @@
# end
#
class AddressableUrlValidator < ActiveModel::EachValidator
+
+ DEFAULT_OPTIONS = { protocols: %w(http https ssh git) }
+
def validate_each(record, attribute, value)
unless valid_url?(value)
record.errors.add(attribute, "must be a valid URL")
@@ -29,15 +32,9 @@ class AddressableUrlValidator < ActiveModel::EachValidator
def valid_url?(value)
return false unless value
- value.strip!
-
valid_protocol?(value) && valid_uri?(value)
end
- def default_options
- @default_options ||= { protocols: %w(http https ssh git) }
- end
-
def valid_uri?(value)
Addressable::URI.parse(value).is_a?(Addressable::URI)
rescue Addressable::URI::InvalidURIError
@@ -45,7 +42,7 @@ class AddressableUrlValidator < ActiveModel::EachValidator
end
def valid_protocol?(value)
- options = default_options.merge(self.options)
- !!(value =~ /\A#{URI.regexp(options[:protocols])}\z/)
+ options = DEFAULT_OPTIONS.merge(self.options)
+ value =~ /\A#{URI.regexp(options[:protocols])}\z/
end
end