Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

content_tag, escape and html5 data attributes #8091

Closed
CloCkWeRX opened this Issue · 3 comments

3 participants

@CloCkWeRX

rails 3.2.1

Define a helper:

  def foo
    options = {
      :data => { :content => 'double"quote"party"' }
    }

    content_tag(:a, '', options)
  end

Invoke in a template

<%= foo %>

Expected result:

<a data-content="double&quot;quote&quot;party&quot;"></a>

The default argument for content_tag's escape param is true.

Actual result:

<a data-content="double"quote"party"></a>
@senny
Owner

In order to skip escaping, your string needs to be html_safe.

@CloCkWeRX

Not trying to skip it in this instance - my expectation was that content_tag would escape the content, including attributes. (If you are saying that it's being passed to html_safe, and that's not detecting the invalid attribute-ness of the data...)

@carlosantoniodasilva

Hey @CloCkWeRX, I've just added some tests to master that ensures this works with tag and content_tag. I've tested in 3-2-stable as well, and it works the same way, it always escapes the data attributes, as you can see here and here.

I'm closing here, if you find this is still an issue somehow, please let us know and give a bit more information so that we can help figuring it out. Thanks.

@carlosantoniodasilva carlosantoniodasilva referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.