Browse files

Brought the domain method in AD http url inline with subdomain where …

…@@tld_length is used by default. Also set the default value of @@tld_length to 1.
  • Loading branch information...
1 parent ecd0310 commit e1e780a31d56f3bf22f13afd92b7e1274bd4b531 @joshk joshk committed with josevalim Nov 16, 2010
Showing with 5 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_dispatch/http/url.rb
  2. +3 −0 actionpack/test/dispatch/request_test.rb
View
3 actionpack/lib/action_dispatch/http/url.rb
@@ -2,6 +2,7 @@ module ActionDispatch
module Http
module URL
mattr_accessor :tld_length
+ self.tld_length = 1
# Returns the complete URL used for this request.
def url
@@ -67,7 +68,7 @@ def server_port
# Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". You can specify
# a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".
- def domain(tld_length = 1)
+ def domain(tld_length = @@tld_length)
return nil unless named_host?(host)
host.split('.').last(1 + tld_length).join('.')
View
3 actionpack/test/dispatch/request_test.rb
@@ -96,6 +96,9 @@ class RequestTest < ActiveSupport::TestCase
request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
assert_equal "rubyonrails.co.uk", request.domain(2)
+ request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk", :tld_length => 2
+ assert_equal "rubyonrails.co.uk", request.domain
+
request = stub_request 'HTTP_HOST' => "192.168.1.200"
assert_nil request.domain

0 comments on commit e1e780a

Please sign in to comment.