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

Issue Type: Patch Created: 2007-10-12T11:47:20.000+0000 Last Updated: 2008-11-13T14:10:10.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Menno Holtkamp (holtkamp) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Log

Related issues: - ZF-4190



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:

<pre class="highlight">
$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:

<pre class="highlight">
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()

<pre class="highlight">
$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)));


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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.