ID: 49731
User updated by: moltendorf at gmail dot com
-Summary: Illegal XML characters allowed (or not turned into
entities) in text nodes.
Reported By: moltendorf at gmail dot com
Status: Open
Bug Type: DOM XML related
PHP Version: 5.2.11
New Comment:
Made title more correct, and the last comment was intended to replace
the existing description for this bug; as invalid characters should be
stripped entirely, or an exception should be thrown (and the text node
not be added), and/or some sort of method should be included to strip
the illegal characters from the input without throwing an exception.
Previous Comments:
------------------------------------------------------------------------
[2009-10-01 06:51:00] moltendorf at gmail dot com
Adding illegal characters to a text node when saved as XML are not
stripped. This breaks the XML, causing it to be "not well-formed" when
viewed by standards-compliant browsers, like Firefox. Even converting
them to NCRs breaks the XML in most browsers.
For reference, the NCR of the "illegal character" included in the
reproduce code is 
------------------------------------------------------------------------
[2009-10-01 06:47:18] moltendorf at gmail dot com
Description:
------------
Adding illegal characters to a text node when saved as XML are not
either converted to NCRs, or stripped. This breaks the XML, causing it
to be "not well-formed" when viewed by standards-compliant browsers,
like Firefox.
Reproduce code:
---------------
<?php
header ('Content-Type: text/xml');
$document = new DOMDocument ('1.0', 'utf-8');
$element = $document -> createElement ('element');
$text = $document -> createTextNode (''); // Please copy and paste
this line directly; it contains special characters that may not display
correctly; and are invalid in XML based on the W3C specification.
$element -> appendChild ($text);
$document -> appendChild ($element);
echo $document -> saveXML ( );
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<element/>
Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?>
<element></element>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49731&edit=1