Fix html-no-unescaped-entities false positive on ActionView tag helpers#1672
Open
bdewater-thatch wants to merge 2 commits intomarcoroth:mainfrom
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.