From 47292cdef7fe9ca21c749c7fe594457ee1c81de6 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 20 Sep 2005 06:44:53 +0000 Subject: 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 --- actionpack/lib/action_controller/request.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') 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 tld_length, 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 tld_length, 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 -- cgit v1.2.3