ZF-2062: Ampersand in message causes warning DOM_Element::__construct() when using Zend_Log_Formatter_Xml()


When using the Zend_Log_Formatter_Xml() formatter during logging, a message which contains an ampersand results in a warning thrown by the constructor of DOM_Element:

$writer = new Zend_Log_Writer_Stream(logfile.xml);
$formatter = new Zend_Log_Formatter_Xml();
$logger = new Zend_Log($writer);

$testString = 'Posted something to server?key=value&key2=value2';
$logger->log($testString, Zend_Log::INFO);

Results in:

Warning: DOMElement::__construct() [function.DOMElement---construct]: unterminated entity reference key2=value2 

The warning can be avoided when the htmlSpecialChars() function is used in Zend_Log_Formatter_Xml::format()

$dom = new DOMDocument();
$elt = $dom->appendChild(new DOMElement($this->_rootElement));

foreach ($dataToInsert as $key => $value) {
    //added htmlSpecialChars function to escape exotic characters
    $elt->appendChild(new DOMElement($key, htmlSpecialChars($value)));


Assigned to Bill

Changing to 'Unassigned'

Resolved in trunk, using htmlspecialchars() on the log-message.

Changing issues in preparation for the 1.7.0 release.