aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-11-08 06:00:22 -0800
committerJosé Valim <jose.valim@gmail.com>2011-11-08 06:00:22 -0800
commit34f61f8b1ddf24e3dcc45b10536fff8eb46b3063 (patch)
tree32df3d9688aa2e334c4038354606245107cd57b2
parent1347665d89d3efb2047b5d872b3ac1e2e132f159 (diff)
parentbd559b00680b6e4c272d4df36f239768750f1a6b (diff)
downloadrails-34f61f8b1ddf24e3dcc45b10536fff8eb46b3063.tar.gz
rails-34f61f8b1ddf24e3dcc45b10536fff8eb46b3063.tar.bz2
rails-34f61f8b1ddf24e3dcc45b10536fff8eb46b3063.zip
Merge pull request #3568 from bfolkens/master-url_subdomain_with_numeric_host
Fix trouble using :subdomain in development environment when using numeric addresses.
-rw-r--r--actionpack/lib/action_dispatch/http/url.rb2
-rw-r--r--actionpack/test/controller/url_for_test.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb
index c8ddd07bfa..129a8b1031 100644
--- a/actionpack/lib/action_dispatch/http/url.rb
+++ b/actionpack/lib/action_dispatch/http/url.rb
@@ -64,7 +64,7 @@ module ActionDispatch
end
def host_or_subdomain_and_domain(options)
- return options[:host] if options[:subdomain].nil? && options[:domain].nil?
+ return options[:host] if !named_host?(options[:host]) || (options[:subdomain].nil? && options[:domain].nil?)
tld_length = options[:tld_length] || @@tld_length
diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb
index 11ced2df2a..dc07e07cb9 100644
--- a/actionpack/test/controller/url_for_test.rb
+++ b/actionpack/test/controller/url_for_test.rb
@@ -16,6 +16,10 @@ module AbstractController
W.default_url_options[:host] = 'www.basecamphq.com'
end
+ def add_numeric_host!
+ W.default_url_options[:host] = '127.0.0.1'
+ end
+
def test_exception_is_thrown_without_host
assert_raise ArgumentError do
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
@@ -81,6 +85,13 @@ module AbstractController
)
end
+ def test_subdomain_may_be_accepted_with_numeric_host
+ add_numeric_host!
+ assert_equal('http://127.0.0.1/c/a/i',
+ W.new.url_for(:subdomain => 'api', :controller => 'c', :action => 'a', :id => 'i')
+ )
+ end
+
def test_domain_may_be_changed
add_host!
assert_equal('http://www.37signals.com/c/a/i',