From:             sergej at halogen-dg dot com
Operating system: FreeBSD, Linux
PHP version:      5.2.5
PHP Bug Type:     SimpleXML related
Bug description:  Ampersand sign in SimpleXMLElement->addChild() causes 
incomplete XML

Description:
------------
SimpleXMLElement->addChild() causes warning message and produces 
incomplete XML in case when the second argument contains ampersand  
sign '&'. Text after ampersand is absent in output XML.

In the same time escaping of other XML special symbols in tag body 
works OK. Also all XML special symbols in tag attributes are escaped 
OK.


Reproduce code:
---------------
<?
$sxml=new SimpleXMLElement('<?xml version="1.0"
encoding="utf-8"?><test></test>');
// Quotes
$sitem=$sxml->addChild('tag',"'");
$sitem->addAttribute('attr',"'");
$sitem=$sxml->addChild('tag','"');
$sitem->addAttribute('attr','"');
// Brackets
$sitem=$sxml->addChild('tag','<');
$sitem->addAttribute('attr','<');
$sitem=$sxml->addChild('tag','>');
$sitem->addAttribute('attr','>');
// Ampersand
$sitem=$sxml->addChild('tag','Smith & Wesson');
$sitem->addAttribute('attr','Smith & Wesson');
// Result XML
print($sxml->asXML());
?>


Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<test><tag attr="'">'</tag><tag attr="&quot;">"</tag><tag 
attr="&lt;">&lt;</tag><tag attr="&gt;">&gt;</tag><tag attr="Smith 
&amp; Wesson">Smith &amp; Wesson</tag></test>


Actual result:
--------------
PHP Warning:  SimpleXMLElement::addChild(): unterminated entity 
reference          Wesson in xml.php on line 14

Warning: SimpleXMLElement::addChild(): unterminated entity reference      
   
Wesson in xml.php on line 14
<?xml version="1.0" encoding="utf-8"?>
<test><tag attr="'">'</tag><tag attr="&quot;">"</tag><tag 
attr="&lt;">&lt;</tag><tag attr="&gt;">&gt;</tag><tag attr="Smith 
&amp; Wesson">Smith </tag></test>


-- 
Edit bug report at http://bugs.php.net/?id=44458&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44458&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44458&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44458&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44458&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44458&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44458&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44458&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44458&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44458&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44458&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44458&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44458&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44458&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44458&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44458&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44458&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44458&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44458&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44458&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44458&r=mysqlcfg

Reply via email to