Repository navigation
Decode HTML character references instead of double-escaping them - #3
Merged
Merged
Conversation
Text and literal attribute values were emitted with their HTML character references intact, and Phlex escapes everything it outputs, so `©` rendered as the visible text "©" (`&copy;`), ` ` as " ", and `href="?a=1&b=2"` as `&amp;`. The ERB Parser now decodes references (HtmlEntities: HTML 4 named set plus `'`, decimal and hex) in Text nodes and in the literal parts of attribute values, letting Phlex re-escape only what needs it. HAML text goes through the same Parser and is fixed too. `<script>`/`<style>` content and HAML's `:escaped` filter stay verbatim; unknown names, unterminated references and invalid code points are left as written. Invisible characters such as a decoded ` ` are written as ` ` escapes in the generated source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
Problem
HTML character references in template text and literal attribute values were copied verbatim into the generated Ruby strings. Phlex escapes everything it outputs, so they were escaped twice:
<p>© 2026</p>p { "© 2026" }<p>&copy; 2026</p>→ shows "© 2026"a b"a b"href="/x?a=1&b=2"href: "/x?a=1&b=2"&amp;in the URLThis affected ERB from the start, and HAML text since #2.
Fix
HtmlEntities.decodeturns references into the characters they stand for. Named references come from the HTML 4 set plus', generated from Python'shtml.entities.name2codepoint; decimal and hex references are supported too.Parserapplies it to Text nodes and to the literal parts of attribute values. Phlex then re-escapes only what needs it:<b>→"<b>"→<b>. HAML text goes through the same parser, so it is fixed as well.<script>/<style>content (RawText);:escapedfilter (literal text by definition);;, and invalid code points.Transformer#escape_innerwrites invisible characters, such as a decoded , asescapes, so the generated source stays readable.After the fix, rendered with Phlex 2.4:
<p title="Tom & Jerry">© 2026 — a b <tag></p><a href="/x?a=1&b=2">Go</a>.Testing
test/html_entities_test.rb(12 tests): decoding rules, ERB text and attributes, interpolated attributes,static_classesafter decoding, script verbatim, and HAML text vs:escaped. Suite: 169 → 181, all green.🤖 Generated with Claude Code