aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/request.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-20 06:44:53 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-20 06:44:53 +0000
commit47292cdef7fe9ca21c749c7fe594457ee1c81de6 (patch)
tree97a2a935484c75f3cb92e6244f8dd68925e0ef3f /actionpack/lib/action_controller/request.rb
parent3e2bac428dab23f7455893b62d78be9817906d25 (diff)
downloadrails-47292cdef7fe9ca21c749c7fe594457ee1c81de6.tar.gz
rails-47292cdef7fe9ca21c749c7fe594457ee1c81de6.tar.bz2
rails-47292cdef7fe9ca21c749c7fe594457ee1c81de6.zip
Fixed that Request#domain caused an exception if the domain header wasn't set in the original http request #1795 [Michael Koziarski]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2270 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/request.rb')
-rwxr-xr-xactionpack/lib/action_controller/request.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 00f411e7be..e5dc424476 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -109,7 +109,7 @@ 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?
+ return nil if !/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.match(host).nil? or host.nil?
host.split('.').last(1 + tld_length).join('.')
end
@@ -118,6 +118,7 @@ module ActionController
# You can specify a different <tt>tld_length</tt>, such as 2 to catch ["www"] instead of ["www", "rubyonrails"]
# in "www.rubyonrails.co.uk".
def subdomains(tld_length = 1)
+ return [] unless host
parts = host.split('.')
parts[0..-(tld_length+2)]
end