-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOMParser does not recognise BODY and thus creates it twice #1615
Comments
@capricorn86 I have created a naive fix for this, I did not handle all the cases - like what happens if there are multiple body elements as siblings / children of body and such. These cases will still fail and would need some rework on how HappyDOM appends / parses the html. The sibling case could be handled by adding the following to the appendChild part of DOMParser, but that wouldn't solve the child case so perhaps it's better to do it in the XMLParser, but at that point it's not an XMLParser, but instead an HTMLParser as XML does not specify that it should not have multiple BODY tags. If performance is not a concern then a naive solution could walk through the output of XMLParser root document tree and remove every child with the tagName body.
|
Describe the bug
DOMParser is not compliant with the browser implementation. This breaks frameworks like Angular from setting the innerHTML as an attribute, breaking most renders using Angular.
This occurs because BODY is not recognised and this causes body to be created as an extra element in HappyDOM.
To Reproduce
(new window.DOMParser()).parseFromString("<body><x></x>Example Text", "text/html").body.innerHTML
HappyDOM:
<body><x></x>Example Text</body>
Expected behavior
Chrome:
<x></x>Example Text
Additional context
tagName BODY should not be created as a standard node.
happy-dom/packages/happy-dom/src/dom-parser/DOMParser.ts
Line 79 in afd256b
happy-dom/packages/happy-dom/src/dom-parser/DOMParser.ts
Line 87 in afd256b
@capricorn86
The text was updated successfully, but these errors were encountered: