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.

There is no way to have an unescaped html in a link title

#3733

Sometimes I use link_to to link an image.

In rails 3 the name is always escaped:

"<a #{href_attr}#{tag_options}>#{ERB::Util.h(name || url)}</a>".html_safe!

Can you add an option to link_to that matches the option on url_for so it accepts :escape like url_for does.

Reported by Sam Saffron · January 18th, 2010 @ 03:20 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)

    If you're going to link to image, use image_tag helper, or just mark your <img> tag has html_safe!

    link_to image_tag('foo.png'), '/go/to/foo'
    
    link_to '<img src="foo.png" />'.html_safe!, '/go/to/foo'
    

    All string that isn't marked as html_safe will always be escaped in Rails 3.

    January 18th, 2010 @ 07:24 AM

  2. Sam Saffron
    Sam Saffron

    Ok makes sense however there is an inconsistency with the implementation of url_for. Does it need that escape logic there ?

    January 18th, 2010 @ 07:38 AM

  3. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)

    I think there's a use case for escape logic there. One of the example would be if you're going to include the url generated from url_for as a parameter in GET request, so it would escape & in the value.

    January 18th, 2010 @ 07:59 AM

  4. José Valim
    José Valim
    • State changed from new to invalid

    January 18th, 2010 @ 08:24 AM