feat(scanner): add HTML entity resolution in SimpleHTMLScanner#22
Merged
feat(scanner): add HTML entity resolution in SimpleHTMLScanner#22
Conversation
Implement resolveEntities() in SimpleHTMLScanner to decode HTML character references in text content and attribute values during parsing. - Handle numeric decimal (Ö), hex (Ö), and named (Ö) entities - Follow HTML5 attribute value state: skip semicolon-less named entities followed by [A-Za-z0-9=] to avoid corrupting URLs (e.g. ¬=, ©=) - Replace invalid code points (null, surrogates, out-of-range, noncharacters) with U+FFFD per HTML5 spec - Update test suite to reflect correct entity-resolved output Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
Implements HTML character entity resolution directly in
SimpleHTMLScanner, decoding entities in both text content and attribute values during parsing.Changes Made
resolveEntities(String text)andresolveEntities(String text, boolean inAttribute)methods toSimpleHTMLScannerENTITY_PATTERNregex covering decimal (Ö), hex (Ö), and named (Ö) entity references with optional trailing semicolonsresolveCodePoint()helper that replaces invalid/noncharacter code points with U+FFFD per the HTML5 speccharacters()events[A-Za-z0-9=]are intentionally left unresolved to avoid corrupting URLs (e.g.¬=,©=)Testing
Breaking Changes
&...;sequences will now be emitted as their decoded Unicode equivalents. Consumers relying on raw entity text in SAX events will need to re-evaluate, but this aligns with correct HTML parsing behavior.Additional Notes
HTMLEntities.get()for named entity lookup — no new dependencies introduced