summaryrefslogtreecommitdiff
path: root/app
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
parent0ca275748314a27a1f36e12fe1360df11c9be25d (diff)
downloadgitlab-ce-5b893d603dd68f263129523f13e8eb68b67fe790.tar.gz
few changes based on feedback
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb4
-rw-r--r--app/validators/addressable_url_validator.rb13
2 files changed, 7 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 2b1b25ab9d2..89ce61b95ec 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -445,11 +445,11 @@ class Project < ActiveRecord::Base
end
def import_url=(value)
+ return super(value) unless Gitlab::UrlSanitizer.valid?(value)
+
import_url = Gitlab::UrlSanitizer.new(value)
create_or_update_import_data(credentials: import_url.credentials)
super(import_url.sanitized_url)
- rescue Addressable::URI::InvalidURIError
- errors.add(:import_url, 'must be a valid URL.')
end
def import_url
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