Permalink
Browse files

only check named_host? once in normalize_host

  • Loading branch information...
1 parent 977a2f3 commit d7f780c30438ac563cd170080ed6e8f434256855 @tenderlove tenderlove committed Jun 12, 2014
Showing with 7 additions and 3 deletions.
  1. +7 −3 actionpack/lib/action_dispatch/http/url.rb
View
10 actionpack/lib/action_dispatch/http/url.rb
@@ -18,8 +18,7 @@ def extract_domain(host, tld_length)
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
@@ -64,6 +63,11 @@ 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?('?')
@@ -131,7 +135,7 @@ def normalize_host(_host, options)
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

0 comments on commit d7f780c

Please sign in to comment.