Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using html_safe or raw inside safe_join is being flagged #3676

Closed
monfresh opened this issue Oct 25, 2016 · 0 comments
Closed

Using html_safe or raw inside safe_join is being flagged #3676

monfresh opened this issue Oct 25, 2016 · 0 comments

Comments

@monfresh
Copy link

Scenario: Elements inside a safe_join call include raw or html_safe, such as:

safe_join([raw(i18n_text), raw(i18n_mode_additional_markup(key))])

or

safe_join([i18n_text.html_safe, i18n_mode_additional_markup(key).html_safe])

In this case, i18n_text is a string returned by I18n.translate, which may or may not include HTML, and i18n_mode_additional_markup(key) returns the following string:

"<small class=\"i18n-anchor\"><a href=\"#{uri}\" " \
"target=\"_blank\" class=\"ml-tiny no-hover-decoration\">🔗</a></small>"

I also tried the content_tag version:

content_tag(:small, class: 'i18n-anchor') do
  content_tag(:a, href: uri, target: '_blank', class: 'ml-tiny no-hover-decoration') do
    '🔗'
  end
end

Expected behavior

Given that the Rails documentation for safe_join shows examples with raw, I would expect that would be accepted.

Actual behavior

Rubocop flags this as an offense:

Tagging a string as html safe may be a security risk, prefer safe_join or other Rails tag helpers instead.
      safe_join([raw(i18n_text), raw(i18n_mode_additional_markup(key))])

Steps to reproduce the problem

Call .html_safe and/or raw inside a safe_join call.

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.44.1 (using Parser 2.3.1.4, running on ruby 2.3.1 x86_64-darwin14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant