You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the course of figuring out a workaround to #84, I decided to looked for some other mechanism that does actually set the "require well-formed" parameter to true when serializing.
My reading is that outerHTML's getter runs the fragment serializing algorithm with the "require well-formed" parameter set to true, and the fragment serializing algorithm specifically produces an XML serialization if the node document is XML, and serializing an XML node serializes its children by specifically calling XML serialization, preserving the "require well-formed" flag in the recursive call. That is, getting .outerHTML on a XML node with an unserializable child should fail. (Note also that outerHTML is documented as "In the case of an XML document, throws a "InvalidStateError"DOMException if the element cannot be serialized to XML.")
But if you try the following code
constxmlDoc=document.implementation.createDocument(null,null);constrootNode=xmlDoc.createElement("root");xmlDoc.appendChild(rootNode);constchildNode=document.createElement("child");childNode.innerHTML='<meta property="og:description" content="I forgot to "escape" this value">';xmlDoc.adoptNode(childNode);rootNode.appendChild(childNode);constresult=rootNode.outerHTML;console.log(result);console.log(newDOMParser().parseFromString(result,"text/xml").querySelector('parsererror').innerHTML);
in Firefox, Safari, and Chrome, .outerHTML does not throw and returns not-well-formed XML, and you can see that DOMParser does not like it.
Am I missing something in the specification that provides for this behavior? I realize I'm doing something tricky by adopting an HTML element into XML, but my reading of the adoption process is that it change's the node's node document, and this is what triggers serializing as XML. In any case, I'm getting .outerHTML of an actual XML node, which should recursively serialize as XML.
I mentioned this over at https://bugzilla.mozilla.org/1914813 and was told that even if this is an implementation bug but all the major implementations happen to do the same thing, the right thing to do is to update the spec, so I'm filing this here.
The text was updated successfully, but these errors were encountered:
In the course of figuring out a workaround to #84, I decided to looked for some other mechanism that does actually set the "require well-formed" parameter to true when serializing.
My reading is that
outerHTML
's getter runs the fragment serializing algorithm with the "require well-formed" parameter set to true, and the fragment serializing algorithm specifically produces an XML serialization if the node document is XML, and serializing an XML node serializes its children by specifically calling XML serialization, preserving the "require well-formed" flag in the recursive call. That is, getting.outerHTML
on a XML node with an unserializable child should fail. (Note also thatouterHTML
is documented as "In the case of an XML document, throws a"InvalidStateError"
DOMException
if the element cannot be serialized to XML.")But if you try the following code
in Firefox, Safari, and Chrome,
.outerHTML
does not throw and returns not-well-formed XML, and you can see thatDOMParser
does not like it.Am I missing something in the specification that provides for this behavior? I realize I'm doing something tricky by adopting an HTML element into XML, but my reading of the adoption process is that it change's the node's node document, and this is what triggers serializing as XML. In any case, I'm getting
.outerHTML
of an actual XML node, which should recursively serialize as XML.I mentioned this over at https://bugzilla.mozilla.org/1914813 and was told that even if this is an implementation bug but all the major implementations happen to do the same thing, the right thing to do is to update the spec, so I'm filing this here.
The text was updated successfully, but these errors were encountered: