ZF-2062: Ampersand in message causes warning DOM_Element::__construct() when using Zend_Log_Formatter_Xml()
Description
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();
$writer->setFormatter($formatter);
$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)));
}
Comments
Posted by Thomas Weidner (thomas) on 2007-10-15T13:46:39.000+0000
Assigned to Bill
Posted by Bill Karwin (bkarwin) on 2007-10-17T15:28:45.000+0000
Changing to 'Unassigned'
Posted by Benjamin Eberlei (beberlei) on 2008-11-07T02:47:49.000+0000
Resolved in trunk, using htmlspecialchars() on the log-message.
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:10.000+0000
Changing issues in preparation for the 1.7.0 release.