Skip to content

Commit

Permalink
Fix appending text to Text node's data in parse5 adaptor
Browse files Browse the repository at this point in the history
The "insert a character" algorithm [1] in the HTML parser is clear on
appending directly to the Text node's data rather than using the replace
data algorithm (which creates mutation records).

[1]: https://html.spec.whatwg.org/multipage/parsing.html#insert-a-character

Fixes: jsdom#3261
  • Loading branch information
TimothyGu authored and domenic committed Jun 13, 2022
1 parent 2e35526 commit 7bd236c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jsdom/browser/parser/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class JSDOMParse5Adapter {
insertText(parentNode, text) {
const { lastChild } = parentNode;
if (lastChild && lastChild.nodeType === nodeTypes.TEXT_NODE) {
lastChild.data += text;
lastChild._data += text;
} else {
const ownerDocument = this._ownerDocument();
const textNode = Text.createImpl(this._globalObject, [], { data: text, ownerDocument });
Expand All @@ -150,7 +150,7 @@ class JSDOMParse5Adapter {
insertTextBefore(parentNode, text, referenceNode) {
const { previousSibling } = referenceNode;
if (previousSibling && previousSibling.nodeType === nodeTypes.TEXT_NODE) {
previousSibling.data += text;
previousSibling._data += text;
} else {
const ownerDocument = this._ownerDocument();
const textNode = Text.createImpl(this._globalObject, [], { data: text, ownerDocument });
Expand Down

0 comments on commit 7bd236c

Please sign in to comment.