Skip to content

Commit 4a92a64

Browse files
committed
Bug fix for issue 1035
#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.
1 parent 8352a97 commit 4a92a64

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

dev/tests/unit/testsuite/Magento/Framework/Simplexml/ElementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public function testAppendChild()
7272
$baseXml = simplexml_load_string('<root/>', 'Magento\Framework\Simplexml\Element');
7373
/** @var \Magento\Framework\Simplexml\Element $appendXml */
7474
$appendXml = simplexml_load_string(
75-
'<node_a attr="abc"><node_b>text</node_b></node_a>',
75+
'<node_a attr="abc"><node_b innerAttribute="xyz">text</node_b></node_a>',
7676
'Magento\Framework\Simplexml\Element'
7777
);
7878
$baseXml->appendChild($appendXml);
7979

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

lib/internal/Magento/Framework/Simplexml/Element.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function xmlentities($value = null)
326326
*/
327327
public function appendChild($source)
328328
{
329-
if ($source->children()) {
329+
if ($source->count()) {
330330
$child = $this->addChild($source->getName());
331331
} else {
332332
$child = $this->addChild($source->getName(), $this->xmlentities($source));

0 commit comments

Comments
 (0)