From 8ed1f2ec201b2de0d929307dbe7fe7ee0d0529d6 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 19 Feb 2010 12:24:49 +0000 Subject: [PATCH 1/2] Don't add two ports in rewrite_url. --- actionpack/lib/action_controller/url_rewriter.rb | 4 ++-- actionpack/test/controller/url_rewriter_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index e4c2a29..db70358 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -177,8 +177,8 @@ 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.delete(:port)}" if options.key?(:port) + rewritten_url << (options[:host] || @request.host) + rewritten_url << (options.key?(:port) ? ":#{options.delete(:port)}" : @request.port_string) end path = rewrite_path(options) diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index fdc4cfa..d36af14 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -15,6 +15,15 @@ class UrlRewriterTests < ActionController::TestCase ) end + def test_no_double_port + request = ActionController::TestRequest.new('HTTP_HOST' => 'test.host:3000') + rewriter = ActionController::UrlRewriter.new(request, @params) + + assert_equal('http://test.host:1271/c/a/i', + rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271) + ) + end + def test_protocol_with_and_without_separator assert_equal('https://test.host/c/a/i', @rewriter.rewrite(:protocol => 'https', :controller => 'c', :action => 'a', :id => 'i') -- 1.6.6.1