From 109b11d988b9d8541f1c38213cf57ace6d155d00 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 20 Aug 2010 09:18:59 +0200 Subject: [PATCH] fix rewritting url with specified port Fix solve issue when rails rewritte just port and site is keep. If site contain port number result was site:old_port:new_port. Fix change the behavior to correct one site:new_port. --- actionpack/lib/action_controller/url_rewriter.rb | 2 +- actionpack/test/controller/url_rewriter_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 552c2ae..5fe07c4 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -188,7 +188,7 @@ module ActionController rewritten_url << (options[:protocol] || @request.protocol) rewritten_url << "://" unless rewritten_url.match("://") rewritten_url << rewrite_authentication(options) - rewritten_url << (options[:host] || @request.host_with_port) + rewritten_url << (options[:host] || options.key?(:port) ? @request.host : @request.host_with_port ) rewritten_url << ":#{options.delete(:port)}" if options.key?(:port) end diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 11add3a..c6a41fc 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -10,6 +10,7 @@ class UrlRewriterTests < ActionController::TestCase end def test_port + @request.port = 3000 #use default rails port assert_equal('http://test.host:1271/c/a/i', @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271) ) -- 1.7.1