From:             brian dot sanders at cometsystems dot com
Operating system: Fedora Core 3
PHP version:      5.0.2
PHP Bug Type:     XML related
Bug description:  ampersands (&) not being translated to entities when setting 
nodeValue

Description:
------------
We have encountered the following bug when using libxml2 (via PHP5):

When we set the value of a text node, ampersands (&) are not being
converted to XML entities.  These raw characters truncate our text node,
resulting in lost data.

For example, after setting nodeValues, less-than's (<) show up as entities
(&lt;) in our XML file.  However, ampersands (&) show up as raw characters
(&). 

Note that in the example code we have silenced the output from setting the
nodeValues, as this generates a PHP warning when used with newer versions
of libxml2.

We have experienced this bug on at least two machines, with the following
configurations:

MACHINE 1:
 LIBXML2: 2.6.16-3 (binary rpm)
 PHP: 5.0.2 (built from source)
 OS: Fedora Core Linux 3
 KERNEL: 2.6.9-1.681_FC3smp

MACHINE 2:
 LIBXML2: 2.6.7-28.4 (binary)
 PHP: 5.0.2 (built from source)
 OS: Suse Linux 9.1
 KERNEL: 2.6.4-52-default 

Reproduce code:
---------------
<?php

/* load the document */
$dom = DomDocument::loadXML(<<<XML
<?xml version="1.0"?>
<test>
 <foo>Here is an &lt; to test.</foo>
 <bar>Here is an &amp; to test.</bar>
</test>
XML
);

/* confirm we have the document verbatim */
print("HERE IS THE INITIAL DOCUMENT:\n\n");
print($dom->saveXML());
print("\n--------------------------------\n\n");

/* get the LT node */
$nodeList = $dom->getElementsByTagName('foo');
$nodeLT = $nodeList->item(0);

/* get the AMP node */
$nodeList = $dom->getElementsByTagName('bar');
$nodeAMP = $nodeList->item(0);

/* resave the node values */
@$nodeLT->nodeValue = $nodeLT->nodeValue;
@$nodeAMP->nodeValue = $nodeAMP->nodeValue;

/* show the altered document */
print("HERE IS THE DOCUMENT AFTER THE SAVE:\n\n");
print($dom->saveXML());
print("\n--------------------------------\n\n");

?>


Expected result:
----------------
HERE IS THE INITIAL DOCUMENT:

<?xml version="1.0"?>
<test>
 <foo>Here is an &lt; to test.</foo>
 <bar>Here is an &amp; to test.</bar>
</test>

--------------------------------

HERE IS THE DOCUMENT AFTER THE SAVE:

<?xml version="1.0"?>

<test>
 <foo>Here is an &lt; to test.</foo>
 <bar>Here is an &amp; to test.</bar>
</test>


Actual result:
--------------
HERE IS THE INITIAL DOCUMENT:

<?xml version="1.0"?>
<test>
 <foo>Here is an &lt; to test.</foo>
 <bar>Here is an &amp; to test.</bar>
</test>

--------------------------------

HERE IS THE DOCUMENT AFTER THE SAVE:

<?xml version="1.0"?>

<test>
 <foo>Here is an &lt; to test.</foo>
 <bar>Here is an </bar>
</test>


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

Reply via email to