aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-01-12 09:25:49 -0800
committerXavier Noria <fxn@hashref.com>2012-01-12 09:25:49 -0800
commitdaf435d20ccdad86de400c4cfaacf54510c7ab6d (patch)
tree69d765502ed792bdf7cf468afa447525d6fbbf35 /actionpack
parente927f06b2528bef52087dd12f012c20ab26fb59c (diff)
parent034bf727190489a9f4cf3643c39b76709d0e0644 (diff)
downloadrails-daf435d20ccdad86de400c4cfaacf54510c7ab6d.tar.gz
rails-daf435d20ccdad86de400c4cfaacf54510c7ab6d.tar.bz2
rails-daf435d20ccdad86de400c4cfaacf54510c7ab6d.zip
Merge pull request #4425 from carlosantoniodasilva/url-for-refactor
Url for refactor
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/url.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb
index 64459836b5..80ffbe575b 100644
--- a/actionpack/lib/action_dispatch/http/url.rb
+++ b/actionpack/lib/action_dispatch/http/url.rb
@@ -1,6 +1,8 @@
module ActionDispatch
module Http
module URL
+ IP_HOST_REGEXP = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
+
mattr_accessor :tld_length
self.tld_length = 1
@@ -21,7 +23,7 @@ module ActionDispatch
end
def url_for(options = {})
- unless options[:host].present? || options[:only_path].present?
+ if options[:host].blank? && options[:only_path].blank?
raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
end
@@ -52,7 +54,7 @@ module ActionDispatch
private
def named_host?(host)
- !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
+ host && IP_HOST_REGEXP !~ host
end
def rewrite_authentication(options)
@@ -167,7 +169,7 @@ module ActionDispatch
# such as 2 to catch <tt>"www"</tt> instead of <tt>"www.rubyonrails"</tt>
# in "www.rubyonrails.co.uk".
def subdomain(tld_length = @@tld_length)
- subdomains(tld_length).join(".")
+ ActionDispatch::Http::URL.extract_subdomain(host, tld_length)
end
end
end