php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44478 Unconsistent behaviour when assigning new nodes
Submitted: 2008-03-19 12:22 UTC Modified: 2008-03-20 16:53 UTC
From: vesko at webstudiobulgaria dot com Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 5.2.5 OS: Debian testing
Private report: No CVE-ID:
 [2008-03-19 12:22 UTC] vesko at webstudiobulgaria dot com
Description:
------------
There is a difference in the way the html entities are handled when the new nodes are assigned in different ways. In case of using addChild method they are decoded, otherwise not.

Reproduce code:
---------------
$xml_element = new simpleXMLElement('<root></root>');
$xml_element->node1 = 'a &#38; b';
$xml_element->addChild('node2','c &#38; d');

print $xml_element->node1;
print $xml_element->node2;


Expected result:
----------------
a &#38; bc &#38; d//both left
or
a & bc & d//both decoded

Actual result:
--------------
a &#38; bc & d//one left and the other decoded

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-19 12:53 UTC] vesko at webstudiobulgaria dot com
Based on:
$xml_element = new simpleXMLElement('<root></root>');
$xml_element['attrib1'] = 'a &#38; b';
$xml_element->addAttribute('attrib2','c &#38; d');

print $xml_element['attrib1'];
print $xml_element['attrib2'];

which gives:
a &#38; bc &#38; d

I guess the correct behaviour is to leave the entities as they are, so in the previous example addChild() gives the wring result.
 [2008-03-19 13:16 UTC] vesko at webstudiobulgaria dot com
And another one:
$xml_element->node1[0] = 'a &#38; b';

decodes the html entities while it should not.
 [2008-03-20 00:22 UTC] felipe@php.net
Simple patch:
http://felipe.ath.cx/diff/bug44478.diff
 [2008-03-20 09:15 UTC] vesko at webstudiobulgaria dot com
Hi Felipe,

Thanks for the patch.
I've tested it against 5.2.5 source. It fixes the case:

$xml_element->addChild('node2','c &#38; d');

but not the case:

$xml_element->node1[0] = 'a &#38; b';//still decodes
 [2008-03-20 11:54 UTC] felipe@php.net
Oh, really. I've updated the patch. :)
 [2008-03-20 12:40 UTC] vesko at webstudiobulgaria dot com
It is fixed now.
I hope the patch will be included in the upcoming 5.2.6 :)
 [2008-03-20 16:53 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

While the direct assignment problem was a bug, the addChild() case works 
as expected. It allows fine grained control over adding content in 
SimpleXML, including setting pre-escaped data.
 [2011-12-05 12:30 UTC] quamis at gmail dot com
This problem is still present in PHP 5.3.6-13ubuntu3.2 with Suhosin-Patch
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 10:02:09 2014 UTC