Repository navigation
fix: merge consecutive ontext pieces into one Text node - #361
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
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.
Fixes #353.
Parsing
<p>a & b</p>produced 3 Text nodes ("a ","&"," b") instead of 1 ("a & b"), because htmlparser2 withdecodeEntities: truecallsontextonce per piece around each character reference and the handler appended a new Text node per call. The HTML parsing algorithm appends each character to the previous Text node ("insert a character"), and jsdom returns one node here.Fix (in
esm/shared/parse-from-string.jsplus the identical logic in the committedcjs/mirror): merge anontextpiece into the previous sibling when it is a Text node (prev[VALUE] += text), otherwise appending a new node as before. CDATA handling is untouched; nothing about serialization, escaping, ornormalize()changed.Tests: regression tests in
test/html/document.jscovering entity merge, multi-entity merge, plain text unchanged, and no merging across element or comment boundaries. New tests failed before the fix ("Expected: 1, Got instead: 3") and pass after;test/html/document.jsand the fullnode test/index.jssuite both exit 0 with no failures. Honest limits: this suite prints no numeric assertion totals, so counts are reported as exit codes + failure-grep counts; eslint/tsc/rollup were not run (devDeps deliberately skipped for disk).Note: the issue reporter offered in the issue body ("If yes, I can open a PR") but has filed nothing as of this PR — no PR by number or concept covers this fix.