Skip to content
Browse files

Merge pull request #4425 from carlosantoniodasilva/url-for-refactor

Url for refactor
  • Loading branch information...
2 parents e927f06 + 034bf72 commit daf435d20ccdad86de400c4cfaacf54510c7ab6d @fxn fxn committed Jan 12, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 actionpack/lib/action_dispatch/http/url.rb
View
8 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 @@ def extract_subdomain(host, tld_length = @@tld_length)
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 @@ def url_for(options = {})
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 @@ def subdomains(tld_length = @@tld_length)
# 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

0 comments on commit daf435d

Please sign in to comment.
Something went wrong with that request. Please try again.