Skip to content

Commit

Permalink
Bug fix for issue 1035
Browse files Browse the repository at this point in the history
#1035

A bug in the appendNode method of Magento\Framework\Simplexml\Element.php causes values to be lost in very specific cases. This will fix it. The existing unit test for appendNode has been updated as well.

Bug: When appending a node that has an attribute and no child nodes, the code will take the code path for having children. This is because the result of $source->children() evaluates to TRUE when a node has attributes and no children.

Fix: Changing to call from [children()] to [count()] fixes the issue.
  • Loading branch information
tim-reynolds committed Feb 15, 2015
1 parent 8352a97 commit 4a92a64
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public function testAppendChild()
$baseXml = simplexml_load_string('<root/>', 'Magento\Framework\Simplexml\Element');
/** @var \Magento\Framework\Simplexml\Element $appendXml */
$appendXml = simplexml_load_string(
'<node_a attr="abc"><node_b>text</node_b></node_a>',
'<node_a attr="abc"><node_b innerAttribute="xyz">text</node_b></node_a>',
'Magento\Framework\Simplexml\Element'
);
$baseXml->appendChild($appendXml);

$expectedXml = '<root><node_a attr="abc"><node_b>text</node_b></node_a></root>';
$expectedXml = '<root><node_a attr="abc"><node_b innerAttribute="xyz">text</node_b></node_a></root>';
$this->assertXmlStringEqualsXmlString($expectedXml, $baseXml->asNiceXml());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Simplexml/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function xmlentities($value = null)
*/
public function appendChild($source)
{
if ($source->children()) {
if ($source->count()) {
$child = $this->addChild($source->getName());
} else {
$child = $this->addChild($source->getName(), $this->xmlentities($source));
Expand Down

0 comments on commit 4a92a64

Please sign in to comment.