aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/request.rb3
-rw-r--r--actionpack/test/controller/request_test.rb6
3 files changed, 10 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 894d06b950..bec8430478 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that Request#domain caused an exception if the domain header wasn't set in the original http request #1795 [Michael Koziarski]
+
* Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103
* Add routing tests from #1945 [ben@groovie.org]
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
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index 2aeff279be..49ce7b80bb 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -47,6 +47,9 @@ class RequestTest < Test::Unit::TestCase
@request.host = "192.168.1.200"
assert_nil @request.domain
+
+ @request.host = nil
+ assert_nil @request.domain
end
def test_subdomains
@@ -61,6 +64,9 @@ class RequestTest < Test::Unit::TestCase
@request.host = "foobar.foobar.com"
assert_equal %w( foobar ), @request.subdomains
+
+ @request.host = nil
+ assert_equal [], @request.subdomains
end
def test_port_string