diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/http/url.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 92aba01b95..a5858758c6 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -13,13 +13,12 @@ module ActionDispatch class << self def extract_domain(host, tld_length) - host.split('.').last(1 + tld_length).join('.') if named_host?(host) + extract_domain_from(host, tld_length) if named_host?(host) end def extract_subdomains(host, tld_length) if named_host?(host) - parts = host.split('.') - parts[0..-(tld_length + 2)] + extract_subdomains_from(host, tld_length) else [] end @@ -60,6 +59,15 @@ module ActionDispatch private + def extract_domain_from(host, tld_length) + host.split('.').last(1 + tld_length).join('.') + end + + def extract_subdomains_from(host, tld_length) + parts = host.split('.') + parts[0..-(tld_length + 2)] + end + def add_trailing_slash(path) # includes querysting if path.include?('?') @@ -120,18 +128,19 @@ module ActionDispatch return _host unless named_host?(_host) tld_length = options[:tld_length] || @@tld_length + subdomain = options.fetch :subdomain, true + domain = options[:domain] host = "" - subdomain = options[:subdomain] - if subdomain == true || !options.key?(:subdomain) - return _host if options[:domain].nil? + if subdomain == true + return _host if domain.nil? - host << extract_subdomain(_host, tld_length) + host << extract_subdomains_from(_host, tld_length).join('.') elsif subdomain host << subdomain.to_param end host << "." unless host.empty? - host << (options[:domain] || extract_domain(_host, tld_length)) + host << (domain || extract_domain_from(_host, tld_length)) host end |