-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
DOMElement::replaceWith()
doesn't replace node with DOMDocumentFragment
but just deletes node or causes wrapping <></>
depending on libxml2 version
#11625
Comments
Wow, the resulting output differs by operating system. <!DOCTYPE HTML>
<html>
<body>
</body>
</html> https://onlinephp.io/c/a552a with PHP 8.2.8: <!DOCTYPE HTML>
<html><body>
<><p>Hi!</p></>
</body></html> This is a wrong result too, |
DOMElement::replaceWith()
doesn't replace node with DOMDocumentFragment
but just delete nodeDOMElement::replaceWith()
doesn't replace node with DOMDocumentFragment
but just deletes node or causes wrapping <></>
depending on the OS
I wonder if the output difference is because of a different libxml2 version. The Windows builds use an older version... So on first sight it looks like two things are going on:
I'll investigate. |
Actually, this isn't a regression at all in PHP 8.2.8, and this does not depend on the OS. I can reproduce this on old PHP 8.1.x versions with a recent libxml2. This only depends on the libxml2 version. Looks like it's simply not defined what happens when you add a document fragment. So depending on the version you'll get nothing, or EDIT: interestingly, having 2 divs caused a segfault previously and leaks now, lovely. |
DOMElement::replaceWith()
doesn't replace node with DOMDocumentFragment
but just deletes node or causes wrapping <></>
depending on the OSDOMElement::replaceWith()
doesn't replace node with DOMDocumentFragment
but just deletes node or causes wrapping <></>
depending on libxml2 version
…DOMDocumentFragment but just deletes node or causes wrapping <></> depending on libxml2 version Depending on the libxml2 version, the behaviour is either to not render the fragment correctly, or to wrap it inside <></>. Fix it by unpacking fragments manually. This has the side effect that we need to move the unlinking check in the replacement function to earlier because the empty child list is now possible in non-error cases. Also fixes a mistake in the linked list management.
Description
The following code:
Resulted in this output:
But I expected this output instead:
It works as expected if I replace the line
$div->replaceWith($fragment);
with$div->replaceWith(...$fragment->childNodes);
.PHP Version
PHP 8.2.8
Operating System
Windows 10 x64.
The text was updated successfully, but these errors were encountered: