Bug #79090 [NEW]: DomDocument in recover mode improperly strips amp after error in XML
| From: | danielkarp at gmail dot com | Date: | Thu, 09 Jan 2020 18:01:56 +0000 |
| Subject: | Bug #79090 [NEW]: DomDocument in recover mode improperly strips amp after error in XML | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224818@lists.php.net to get a copy of this message | ||
From: danielkarp at gmail dot com
Operating system: CentOS
PHP version: 7.4.1
Package: DOM XML related
Bug Type: Bug
Bug description:DomDocument in recover mode improperly strips amp after error in XML
Description:
------------
Using DomDocument to recover malformed XML (mismatched tags). In an XML
file, AFTER mismatched tags are repaired (but not before), & 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: &
<foo> baz: <bar>foobar</foo></bar>
No amp? &
</xml>
EOT;
$domDocument->loadXML( $xml );
echo "<br><br>";
echo htmlspecialchars( $domDocument->saveXml());
?>
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?> <xml> Amp: &
<foo> baz:
<bar>foobar</bar></foo> No amp? & </xml>
Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?> <xml> Amp: &
<foo> baz:
<bar>foobar</bar></foo> No amp? </xml>
--
Edit bug report at https://bugs.php.net/bug.php?id=79090&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79090&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79090&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79090&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79090&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79090&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79090&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79090&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79090&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79090&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79090&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79090&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79090&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79090&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79090&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79090&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79090&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79090&r=mysqlcfg