Skip to content

False positive for Rails/OutputSafety in Multiline Heredoc #1553

@dari-us

Description

@dari-us

For multiline heredocs, Rails/OutputSafety complains when calling #html_safe.
Single line heredocs are no problem, though.
It is a "heredoc literal", i.e. I am not using interpolations.


Steps to reproduce the problem

# registers offense
<<~HTML.html_safe
  <h1>nice content</h1>
  <h1>this is cool too</h1>
HTML

# registers no offense
<<~HTML.html_safe
  <h1>nice content</h1>
HTML

Expected behavior

Rails/OutputSafety should not register an offense for any of the above examples.

Actual behavior

Rails/OutputSafety registers an offense for the multiline heredoc.

RuboCop version

$ [bundle exec] rubocop -V
1.81.7 (using Parser 3.3.10.0, Prism 1.6.0, rubocop-ast 1.48.0, analyzing as Ruby 3.4, running on ruby 3.4.7) [x86_64-linux]
  - rubocop-packaging 0.6.0
  - rubocop-minitest 0.38.2
  - rubocop-performance 1.26.1
  - rubocop-rails 2.33.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions