From 7321c8fd96b22c6806b36263aa00dad117106bcc Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Tue, 23 Apr 2013 20:53:21 -0700 Subject: [PATCH 1/2] Update Gemfile source --- Gemfile | 2 +- Gemfile.lock | 72 +++++++++++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index b6a9705..f35b878 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' gem 'addressable', :require => 'addressable/uri' # for unicode URIs gem 'activesupport' diff --git a/Gemfile.lock b/Gemfile.lock index bbf69f5..b39355a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,43 +1,47 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - RedCloth (4.2.7) - activemodel (3.0.7) - activesupport (= 3.0.7) - builder (~> 2.1.2) - i18n (~> 0.5.0) - activerecord (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activesupport (3.0.7) - addressable (2.2.6) - arel (2.0.10) - builder (2.1.2) - diff-lcs (1.1.2) + RedCloth (4.2.9) + activemodel (3.2.13) + activesupport (= 3.2.13) + builder (~> 3.0.0) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activesupport (3.2.13) + i18n (= 0.6.1) + multi_json (~> 1.0) + addressable (2.3.4) + arel (3.0.2) + builder (3.0.4) + diff-lcs (1.2.4) git (1.2.5) - httpi (0.9.4) - pyu-ntlm-http (>= 0.1.3.1) + httpi (2.0.2) rack - i18n (0.5.0) - jeweler (1.6.0) - bundler (~> 1.0.0) + i18n (0.6.1) + jeweler (1.8.4) + bundler (~> 1.0) git (>= 1.2.5) rake - pyu-ntlm-http (0.1.3.1) - rack (1.3.0) - rake (0.9.0) - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.3) - rspec-expectations (2.6.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) - tzinfo (0.3.27) - yard (0.7.1) + rdoc + json (1.7.7) + multi_json (1.7.2) + rack (1.5.2) + rake (10.0.4) + rdoc (4.0.1) + json (~> 1.4) + rspec (2.13.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) + rspec-core (2.13.1) + rspec-expectations (2.13.0) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.13.1) + tzinfo (0.3.37) + yard (0.8.6.1) PLATFORMS ruby From db193d236478d1d2a7e88b21f27662b6278e20da Mon Sep 17 00:00:00 2001 From: Guillaume BELLEGUIC Date: Thu, 22 Aug 2013 15:22:22 +0200 Subject: [PATCH 2/2] fix : undefined method 'scheme' for nil:NilClass if value is nil --- lib/url_validation.rb | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/url_validation.rb b/lib/url_validation.rb index 0313568..bb383b9 100644 --- a/lib/url_validation.rb +++ b/lib/url_validation.rb @@ -116,28 +116,29 @@ class UrlValidator < ActiveModel::EachValidator :insufficient_storage => 507, :not_extended => 510 } - - + + # @private def validate_each(record, attribute, value) return if options[:allow_nil] and value.nil? return if options[:allow_blank] and value.blank? - - uri = Addressable::URI.parse(value) - if uri.scheme.nil? and options[:default_scheme] then - uri = Addressable::URI.parse("#{options[:default_scheme]}://#{value}") + + if uri = Addressable::URI.parse(value) + if uri.scheme.nil? and options[:default_scheme] then + uri = Addressable::URI.parse("#{options[:default_scheme]}://#{value}") + end + + record.errors.add(attribute, options[:invalid_url_message] || :invalid_url) unless url_format_valid?(uri, options) + record.errors.add(attribute, options[:url_not_accessible_message] || :url_not_accessible) unless response = url_accessible?(uri, options) + record.errors.add(attribute, options[:url_invalid_response_message] || :url_invalid_response) unless url_response_valid?(response, record, attribute, value, options) end - - record.errors.add(attribute, options[:invalid_url_message] || :invalid_url) unless url_format_valid?(uri, options) - record.errors.add(attribute, options[:url_not_accessible_message] || :url_not_accessible) unless response = url_accessible?(uri, options) - record.errors.add(attribute, options[:url_invalid_response_message] || :url_invalid_response) unless url_response_valid?(response, record, attribute, value, options) end - + private - + def url_format_valid?(uri, options) return false unless Array.wrap(options[:scheme] || %w( http https )).include?(uri.scheme) - + case uri.scheme when 'http', 'https' return http_url_format_valid?(uri) @@ -145,20 +146,20 @@ def url_format_valid?(uri, options) return true end end - + def http_url_format_valid?(uri) uri.host.present? and not uri.path.nil? end - + def url_accessible?(uri, options) return true unless options[:check_host] or options[:check_path] - + check_host = options[:check_host] check_host ||= %w( http https ) if options[:check_path] if (schemes = Array.wrap(check_host)) and schemes.all? { |scheme| scheme.kind_of?(String) } then return true unless schemes.include?(uri.scheme) end - + case uri.scheme when 'http', 'https' return http_url_accessible?(uri, options) @@ -174,7 +175,7 @@ def http_url_accessible?(uri, options) rescue return false end - + def url_response_valid?(response, record, attribute, value, options) return true unless response.kind_of?(HTTPI::Response) and options[:check_path] options[:response_callback].call(response, record, attribute, value) if options[:response_callback].respond_to?(:call)