php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23710 Handling of XML entites in set_content() is inconsistent
Submitted: 2003-05-20 04:05 UTC Modified: 2003-05-20 11:27 UTC
From: flying at dom dot natm dot ru Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.2RC3 OS: All
Private report: No CVE-ID: None
 [2003-05-20 04:05 UTC] flying at dom dot natm dot ru
set_content() handles XML entities differently, depending on context. Take a look at following example:

<?php
$xml = domxml_new_doc('1.0');
$root = $xml->append_child($xml->create_element('root'));
$root->set_content('&#160;');
$root->set_content('&#160;');
echo $xml->dumpmem();
?>

It produces following document:

<?xml version="1.0"?>
<root>&#160;&amp;#160;</root>

 Note, that first entity was determined as entity, but second - as plain text, and hence quoted. Problem is in php_domxml.c, function domxml_node_set_content(), around line 2734 (as for version) 1.218.2.23:

if (nodep->children) {
	xmlNodeAddContentLen(nodep, content, content_len);
} else {
	xmlNodeSetContentLen(nodep, content, content_len);
}

 If you'll take a look into source of these functions in libxml (file tree.c) - you will see, that xmlNodeSetContentLen() parses given content for entities, while xmlNodeAddContentLen() - not. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-20 11:27 UTC] chregu@php.net
set_content is buggy as hell, if you use it twice...

my advice. use it only once or use the proper DOM methods (create_text_node and append_child).

I won't fix it, since domxml support will be phased out in PHP5 and we're currently focusing on a new, much better dom-and-xml-in-general extension.

chregu
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 17:01:28 2024 UTC