Skip to content


content_tag, escape and html5 data attributes #8091

CloCkWeRX opened this Issue · 3 comments

3 participants


rails 3.2.1

Define a helper:

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

    content_tag(:a, '', options)

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>
Ruby on Rails member

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


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...)

Ruby on Rails member

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.

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.