mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
AbstractRequest#domain returns nil when host is an ip address #2012 [kevin.clark@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2098 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
d54aea29fc
commit
6c44d35268
3 changed files with 7 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* AbstractRequest#domain returns nil when host is an ip address #2012 [kevin.clark@gmail.com]
|
||||
|
||||
* ActionController documentation update #2051 [fbeausoleil@ftml.net]
|
||||
|
||||
* Yield @content_for_ variables to templates #2058 [Sam Stephenson]
|
||||
|
|
|
@ -109,6 +109,8 @@ module ActionController
|
|||
# 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)
|
||||
return nil if !/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.match(host).nil?
|
||||
|
||||
host.split('.').last(1 + tld_length).join('.')
|
||||
end
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@ class RequestTest < Test::Unit::TestCase
|
|||
|
||||
@request.host = "www.rubyonrails.co.uk"
|
||||
assert_equal "rubyonrails.co.uk", @request.domain(2)
|
||||
|
||||
@request.host = "192.168.1.200"
|
||||
assert_nil @request.domain
|
||||
end
|
||||
|
||||
def test_subdomains
|
||||
|
|
Loading…
Reference in a new issue