Skip to content

Commit 075bab4

Browse files
authored
Push textContent also for CDATA_SECTION_NODE nodes (#296)
* test: assert CDATA sections are included when calling textContent * fix: push textContent also for CDATA_SECTION_NODE nodes
1 parent 71399b5 commit 075bab4

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

cjs/interface/element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class Element extends ParentNode {
182182
const text = [];
183183
let {[NEXT]: next, [END]: end} = this;
184184
while (next !== end) {
185-
if (next.nodeType === TEXT_NODE)
185+
const nodeType = next.nodeType;
186+
if (nodeType === TEXT_NODE || nodeType === CDATA_SECTION_NODE)
186187
text.push(next.textContent);
187188
next = next[NEXT];
188189
}

esm/interface/element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ export class Element extends ParentNode {
184184
const text = [];
185185
let {[NEXT]: next, [END]: end} = this;
186186
while (next !== end) {
187-
if (next.nodeType === TEXT_NODE)
187+
const nodeType = next.nodeType;
188+
if (nodeType === TEXT_NODE || nodeType === CDATA_SECTION_NODE)
188189
text.push(next.textContent);
189190
next = next[NEXT];
190191
}

test/interface/cdata-section.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ let document = (new DOMParser).parseFromString('<html><body><![CDATA[test]]>text
88
const [cdata, text] = document.documentElement.lastChild.childNodes;
99

1010
assert(JSON.stringify(cdata.cloneNode()), '[4,"test"]');
11-
1211
assert(JSON.stringify(text.cloneNode()), '[3,"text"]');
1312

13+
assert(document.documentElement.textContent, 'testtext');
14+
1415
assert(text.data, 'text');
1516
assert(text.nodeValue, 'text');
1617
assert(text.textContent, 'text');
@@ -34,4 +35,4 @@ document = (new DOMParser).parseFromString('<?xml version="1.0" encoding="utf-8"
3435
assert(document.toString(), '<?xml version="1.0" encoding="utf-8"?><html><body><![CDATA[cdata with a <div> tag]]></body></html>');
3536

3637
document = (new DOMParser).parseFromString('<?xml version="1.0" encoding="utf-8"?><html><body><script>/*<![CDATA[*/test/*]]>*/</script></body></html>', 'text/xml');
37-
assert(document.toString(), '<?xml version="1.0" encoding="utf-8"?><html><body><script>/*<![CDATA[*/test/*]]>*/</script></body></html>');
38+
assert(document.toString(), '<?xml version="1.0" encoding="utf-8"?><html><body><script>/*<![CDATA[*/test/*]]>*/</script></body></html>');

worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7764,7 +7764,8 @@ let Element$1 = class Element extends ParentNode {
77647764
const text = [];
77657765
let {[NEXT]: next, [END]: end} = this;
77667766
while (next !== end) {
7767-
if (next.nodeType === TEXT_NODE)
7767+
const nodeType = next.nodeType;
7768+
if (nodeType === TEXT_NODE || nodeType === CDATA_SECTION_NODE)
77687769
text.push(next.textContent);
77697770
next = next[NEXT];
77707771
}

0 commit comments

Comments
 (0)