Edit report at https://bugs.php.net/bug.php?id=44458&edit=1

 ID:                 44458
 Comment by:         phpbug at mailinator dot com
 Reported by:        sergej at halogen-dg dot com
 Summary:            Ampersand sign in SimpleXMLElement->addChild()
                     causes incomplete XML
 Status:             Not a bug
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   FreeBSD, Linux
 PHP Version:        5.2.5
 Block user comment: N
 Private report:     N

 New Comment:

That's reply not user friendly :) Absolutely.
It's weired to give link to PHP manual. Why don't you give link to the page 
with description of this "feature"?
http://www.php.net/manual/en/simplexmlelement.addchild.php - this page doesn't 
have any info about ampersand (not counting user comments).
So, till addChild escapes angle brackets, quotes, but doesn't escape ampersand 
- I think every man of good sense will consider this as bug. (SimpleXML is 
Simple? ORLY?)


Previous Comments:
------------------------------------------------------------------------
[2008-03-18 12:13:22] rricha...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

& must be escaped

------------------------------------------------------------------------
[2008-03-17 19:29:53] sergej at halogen-dg dot com

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 this bug report at https://bugs.php.net/bug.php?id=44458&edit=1

Reply via email to