This project is archived and is in readonly mode.

#1106 ✓stale
Dag Arneson

rewrite_url adds port twice

Reported by Dag Arneson | September 24th, 2008 @ 08:43 PM | in 3.x

I discovered that sometimes url_for was giving me urls like "http://localhost:3000:3000/foo" and I tracked it to action_controller/url_rewriter.rb where we have (comments are mine):

  def rewrite_url(options)
    rewritten_url = ""

    unless options[:only_path]
      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) # Note: WITH PORT
      rewritten_url << ":#{options.delete(:port)}" if options.key?(:port) # if options[:port] is set, but options[:host] is not, we get port twice
    end

....

The solution is to use @request.host instead of @request.host_with_port, and to use a similar fallback for the port

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages