Class: RuboCop::Cop::Bridgetown::InsecureHeredoc

Inherits:
Base
  • Object
show all
Includes:
Heredoc
Defined in:
lib/rubocop/cop/bridgetown/insecure_heredoc.rb

Constant Summary collapse

MSG =
"Insecure heredoc detected. Use `html`, `html_map`, `html_attributes`, `text`, " \
"or `render` inside interpolations."

Instance Method Summary collapse

Instance Method Details

#on_heredoc(node) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/bridgetown/insecure_heredoc.rb', line 12

def on_heredoc(node)
  return unless node.source.match?(%r!(HTML|MARKDOWN)$!) &&
    heredoc_body(node).match?(
      %r%[^\\]#\{(?!\s*?(html|html_map|html_attributes|text|render)[ \-\(])% # rubocop:todo Style/RedundantRegexpEscape
    )

  add_offense(node, message: MSG)
end