Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Protocol-relative URLs

#5774

ActionPack doesn't support the generation of protocol-relative URLs right now, e.g. "//google.com", which the browser will follow with "http" or "https", accordingly.

I've found protocol-relative URLs to be especially helpful when providing embed code for users, simplifying the logic to load JS off the right protocol.

This patch adds support and tests the following methods of attaining protocol-relative URLs:

    embed_code_path(@widget, :protocol => false)
    embed_code_path(@widget, :protocol => '//')

The patch also fixes the case where a protocol may be declared with ":" as the separator (e.g., "http:", as JavaScript provides).

Reported by Stephen Celis · October 9th, 2010 @ 03:33 PM

State: committed
Milestone: 3.1
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Andrea Campi
    Andrea Campi

    Did you forget to attach the patch? :)

    October 9th, 2010 @ 06:34 PM

  2. Stephen Celis
  3. Stephen Celis
    Stephen Celis

    A WebKit nightly was giving me technical difficulties on Lighthouse. Attached :)

    October 9th, 2010 @ 07:47 PM

  4. Andrea Campi
    Andrea Campi

    The patch looks good to me functionality-wise, but I have to say I'm not a big fan of:

    unless options[:protocol] == false
    

    If I were to keep changes minimal, I'd write it as:

    if protocol = options[:protocol].nil? ? 'http' : options[:protocol]
      rewritten_url << protocol
    

    My preference would actually be to move the default protocol to default_url_options in #initialize, which would simplify things--but that may be too invasive a change.

    October 9th, 2010 @ 09:15 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:30 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:31 PM

  7. Stephen Celis
    Stephen Celis
    • State changed from stale to open
    • Assigned user set to Santiago Pastorino

    [state:open]

    This isn't a bug, it's a feature and I think it's still valid.

    February 2nd, 2011 @ 04:55 PM

  8. Santiago Pastorino
    Santiago Pastorino
    • Milestone set to 3.1
    • Importance changed from to Low

    Great, can you rebase the patch against master I'm going to apply it.

    February 2nd, 2011 @ 08:12 PM

  9. Stephen Celis
  10. Repository
    Repository
    • State changed from open to committed

    February 2nd, 2011 @ 09:10 PM