From 31e2a2d9bbe3a375912223c133ba793b72600a9f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 7 Nov 2007 14:57:51 +0000 Subject: Fixed handling of non-domain hosts (closes #9479) [purp] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 935e3e08ae..8cfb6d3354 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -191,7 +191,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? or host.nil? + return nil unless named_host?(host) host.split('.').last(1 + tld_length).join('.') end @@ -200,7 +200,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 + return [] unless named_host?(host) parts = host.split('.') parts[0..-(tld_length+2)] end @@ -387,6 +387,10 @@ module ActionController "backtrace" => e.backtrace } end + def named_host?(host) + !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host)) + end + class << self def parse_query_parameters(query_string) return {} if query_string.blank? -- cgit v1.2.3