Bug #79090 [Opn->Wfx]: DomDocument in recover mode improperly strips amp after error in XML

From: Date: Thu, 16 Jan 2020 08:45:26 +0000
Subject: Bug #79090 [Opn->Wfx]: DomDocument in recover mode improperly strips amp after error in XML
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224927@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79090&edit=1 ID: 79090 Updated by: sjon@php.net Reported by: danielkarp at gmail dot com Summary: DomDocument in recover mode improperly strips amp after error in XML -Status: Open +Status: Wont fix Type: Bug Package: DOM XML related Operating System: CentOS PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: I can confirm this bug - but it is not caused by PHP, this is apparently a bug in libxml itself, which you can verify by using xmllint --recover on the cli. It might be a duplicate of https://bugzilla.gnome.org/show_bug.cgi?id=750762 Previous Comments: ------------------------------------------------------------------------ [2020-01-09 18:01:56] danielkarp at gmail dot com Description: ------------ Using DomDocument to recover malformed XML (mismatched tags). In an XML file, AFTER mismatched tags are repaired (but not before), &amp; is improperly stripped from the file. Note, I selected 7.4.1 above, but I've tested this only in 7.4.0. But this is a longstanding bug going back to at least 7.2. You can also see an example here: https://code.sololearn.com/wAQh3FwVdYGO Test script: --------------- <?php $d = new DomDocument(); $domDocument = new DOMDocument( '1.0', 'utf-8' ); $domDocument->recover = true; $xml = <<<EOT <?xml version="1.0" encoding="utf-8"?> <xml> Amp: &amp; <foo> baz: <bar>foobar</foo></bar> No amp? &amp; </xml> EOT; $domDocument->loadXML( $xml ); echo "<br><br>"; echo htmlspecialchars( $domDocument->saveXml()); ?> Expected result: ---------------- <?xml version="1.0" encoding="utf-8"?> <xml> Amp: &amp; <foo> baz: <bar>foobar</bar></foo> No amp? &amp; </xml> Actual result: -------------- <?xml version="1.0" encoding="utf-8"?> <xml> Amp: &amp; <foo> baz: <bar>foobar</bar></foo> No amp? </xml> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79090&edit=1

« previous php.bugs (#224927) next »