diff --git a/src/Formatter/Xml.php b/src/Formatter/Xml.php index 1e519c00..64bb6da2 100644 --- a/src/Formatter/Xml.php +++ b/src/Formatter/Xml.php @@ -153,7 +153,7 @@ public function format($event) ) { if ($key == "message") { $value = htmlspecialchars($value, ENT_COMPAT, $enc); - } elseif($key == "extra" && empty($value)) { + } elseif ($key == "extra" && empty($value)) { continue; } $elt->appendChild(new DOMElement($key, (string)$value)); diff --git a/test/Formatter/XmlTest.php b/test/Formatter/XmlTest.php index dc58a41c..660aeaee 100644 --- a/test/Formatter/XmlTest.php +++ b/test/Formatter/XmlTest.php @@ -178,4 +178,23 @@ public function testObjectsWithStringSerializationAreIncludedInFormattedString() $output = $formatter->format($event); $this->assertContains($expected, $output); } + + /** + * @group ZF2-453 + */ + public function testFormatWillRemoveExtraEmptyArrayFromEvent() + { + $formatter = new XmlFormatter; + $d = new DateTime('2001-01-01T12:00:00-06:00'); + $event = array( + 'timestamp' => $d, + 'message' => 'test', + 'priority' => 1, + 'priorityName' => 'CRIT', + 'extra' => array() + ); + $expected = '2001-01-01T12:00:00-06:00test1CRIT'; + $expected .= PHP_EOL . PHP_EOL; + $this->assertEquals($expected, $formatter->format($event)); + } }