Skip to content

Fix html-no-unescaped-entities false positive on ActionView tag helpers#1672

Open
bdewater-thatch wants to merge 2 commits intomarcoroth:mainfrom
bdewater-thatch:fix/html-no-unescaped-entities-actionview-helpers
Open

Fix html-no-unescaped-entities false positive on ActionView tag helpers#1672
bdewater-thatch wants to merge 2 commits intomarcoroth:mainfrom
bdewater-thatch:fix/html-no-unescaped-entities-actionview-helpers

Conversation

@bdewater-thatch
Copy link
Copy Markdown

@bdewater-thatch bdewater-thatch commented Apr 22, 2026

#1670 was actually correct, the agent hallucinated the rule being enabled or not 😂

The html-no-unescaped-entities rule flags & characters inside string arguments to ActionView tag helpers that auto-escape their content by default. Following the suggested fix (&) causes double-escaping and the user sees literal & instead of &.

Decided to let it take a stab at fixing it because I don't want people to get too comfortable with disabling this rule.

bdewater-thatch and others added 2 commits April 22, 2026 12:39
ActionView tag helpers (tag.p, content_tag, link_to, etc.) auto-escape
their string argument content by default. The rule was incorrectly
flagging unescaped `&` characters inside these helpers' string arguments,
even though the rendered HTML would already be properly escaped.

The fix distinguishes between two cases by checking both `element_source`
and `close_tag` type on the parent HTMLElementNode:

1. String arguments (virtual close tag) — content is auto-escaped by
   the helper, so offenses are suppressed.
2. Block bodies (ERB end node) — content is literal template HTML that
   is NOT auto-escaped, so offenses are still reported.

Known limitation: when `escape: false` is explicitly passed (e.g.
`tag.p("...", escape: false)`), the parser does not expose this in the
AST, so these false negatives cannot be caught yet.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Propagate the `escape` argument from ActionView tag helpers onto the
HTMLElementNode AST node. This allows the linter to distinguish between
helpers that auto-escape content (default) and those where escaping is
explicitly disabled.

The parser extracts the escape value from:
- Keyword argument: `tag.p("...", escape: false)`
- Positional argument: `content_tag(:p, "...", {}, false)`

The `escape_content` field defaults to `true` for all elements. The
linter's `html-no-unescaped-entities` rule now uses this field to
correctly flag offenses when `escape: false` or `escape: nil` is passed.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@bdewater-thatch bdewater-thatch changed the title Fix/html no unescaped entities actionview helpers Fix html-no-unescaped-entities false positive on ActionView tag helpers Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant