Created attachment 45855 [details] Testcase showing invalid merging behavior As the attached testcase demonstrates, Webkit violates the DOM Specification by merging adjacent CDATA sections into Text nodes when normalize() is used. The 'normalize()' method in the DOM Level 2 specification says: "Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes". Further, section 1.3 describing CDATA sections state that adjacent CDATA sections are not to be merged with each other when normalize() is used: "Adjacent CDATASection nodes are not merged by use of the normalize method of the Node interface" The attached testcase shows that the XML chunk starts out with 3 nodes under the document element in this order: - Text node - CDATA Section node - Text node and confirms that the document element has 3 child nodes before normalization and 1 child node after normalization (when it should still have 3, having preserved the above structure). This test passes on Mozilla and IE. This is failing on the latest Webkit build I have: build 52571. Cheers, - Bill
Looking at Node::normalize it seems the problem is using nodeType which returns TEXT_NODE for both text nodes and character data nodes. Instead we should call isTextNode and isElementNode in that function.
Turns out I had it backwards. CDATASection nodes are text nodes. So we need to call nodeType more, not less.
I’ll fix this.
Created attachment 45947 [details] patch
http://trac.webkit.org/changeset/52840
That was fast! Thanks Darin! Cheers, - Bill
Mass moving XML DOM bugs to the "DOM" Component.