From 3585ec538e38ffe27525559ffea2cac05a1351ec Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 19 Feb 2010 13:45:48 +0000 Subject: [PATCH 2/2] Reset the port in rewrite_url if the protocol is changing. --- actionpack/lib/action_controller/url_rewriter.rb | 7 ++++++- actionpack/test/controller/url_rewriter_test.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index db70358..6da26dc 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -178,7 +178,12 @@ module ActionController rewritten_url << "://" unless rewritten_url.match("://") rewritten_url << rewrite_authentication(options) rewritten_url << (options[:host] || @request.host) - rewritten_url << (options.key?(:port) ? ":#{options.delete(:port)}" : @request.port_string) + + if options.key?(:port) + rewritten_url << ":#{options.delete(:port)}" + elsif !options[:protocol] || options[:protocol] == @request.protocol.chomp('://') + rewritten_url << @request.port_string + end end path = rewrite_path(options) diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index d36af14..59d8a37 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -24,6 +24,15 @@ class UrlRewriterTests < ActionController::TestCase ) end + def test_protocol_change_resets_port + request = ActionController::TestRequest.new('HTTP_HOST' => 'test.host:3000') + rewriter = ActionController::UrlRewriter.new(request, @params) + + assert_equal('https://test.host/c/a/i', + rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') + ) + 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.7.0