Changeset 6235
- Timestamp:
- 02/25/07 20:22:09 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/url_rewriter.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/url_rewriter_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6233 r6235 1 1 *SVN* 2 3 * Added :port and :host handling to UrlRewriter (which unified url_for usage, regardless of whether it's called in view or controller) #7616 [alancfrancis] 2 4 3 5 * Allow send_file/send_data to use a registered mime type as the :type parameter #7620 [jonathan] trunk/actionpack/lib/action_controller/url_rewriter.rb
r6053 r6235 44 44 unless options.delete :only_path 45 45 url << (options.delete(:protocol) || 'http') 46 url << '://' 46 url << '://' unless url.match("://") #dont add separator if its already been specified in :protocol 47 47 48 48 raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host] … … 61 61 # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. 62 62 class UrlRewriter #:nodoc: 63 RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, : trailing_slash, :skip_relative_url_root]63 RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :skip_relative_url_root] 64 64 def initialize(request, parameters) 65 65 @request, @parameters = request, parameters … … 81 81 unless options[:only_path] 82 82 rewritten_url << (options[:protocol] || @request.protocol) 83 rewritten_url << "://" unless rewritten_url.match("://") 83 84 rewritten_url << (options[:host] || @request.host_with_port) 85 rewritten_url << ":#{options.delete(:port)}" if options.key?(:port) 84 86 end 85 87 trunk/actionpack/test/controller/url_rewriter_test.rb
r6053 r6235 8 8 end 9 9 10 def test_port 11 assert_equal('http://test.host:1271/c/a/i', 12 @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271) 13 ) 14 end 15 16 def test_protocol_with_and_without_separator 17 assert_equal('https://test.host/c/a/i', 18 @rewriter.rewrite(:protocol => 'https', :controller => 'c', :action => 'a', :id => 'i') 19 ) 20 21 assert_equal('https://test.host/c/a/i', 22 @rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i') 23 ) 24 end 25 10 26 def test_overwrite_params 11 27 @params[:controller] = 'hi' … … 86 102 end 87 103 104 def test_protocol_with_and_without_separator 105 add_host! 106 assert_equal('https://www.basecamphq.com/c/a/i', 107 W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') 108 ) 109 assert_equal('https://www.basecamphq.com/c/a/i', 110 W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://') 111 ) 112 end 113 88 114 def test_named_route 89 115 ActionController::Routing::Routes.draw do |map|