It seems like the XHTML document parser does not include comments and processing instructions which are valid nodes and hence should be in Node.childNodes
. It also seems to treat CDATA sections as Text nodes when that shouldn't be the case.
Considering the following document (making sure the file extension is .xhtml
):
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document</title>
</head>
<body>
<div id="elem"><![CDATA[beep]]><?test test?><!-- I am a comment --><p>Hello</p><p>World</p></div>
<script>
console.log(elem.childNodes.length)
console.log(`${elem.childNodes[0].toString()}, ${elem.childNodes[0].nodeType}`)
console.log(`${elem.childNodes[1].toString()}, ${elem.childNodes[2].toString()}`)
</script>
</body>
</html>
On Firefox 128 (Windows), this outputs:
5
[object CDATASection], 4
[object ProcessingInstruction], [object Comment]
On Ladybird commit cdb9081
(WSL2/Ubuntu 24.04), however, this outputs:
3
[object Text], 3
[object HTMLParagraphElement], [object HTMLParagraphElement]
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too