Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
If you try to add a block to a core/text_list, you'll get unexpected behavior if another block has been defined with the same name or alias. I consider this a bug because it's not that both blocks are rendered, but the second block is rendered twice.
While the first block will be overwritten by $this->_children[$alias] = $block;, a duplicate array element will be added to $this->_sortedChildren.
Then when we loop through the sorted children in Mage_Core_Block_Text_List, we will encounter the block name test_a twice, call getBlock('test_a') twice, and run toHtml() twice.
You could just not add duplicate block names, but it's actually useful if you want to override a block in a more specific handle without having to add <action method="unsetChild">.
I also replaced unset() with array_splice() in the unsetChild method. This seems like a better solution than the solution merged from PR #1108 which I reverted.
Description (*)
If you try to add a block to a
core/text_list
, you'll get unexpected behavior if another block has been defined with the same name or alias. I consider this a bug because it's not that both blocks are rendered, but the second block is rendered twice.For example, this renders "ÄÄ":
While the first block will be overwritten by
$this->_children[$alias] = $block;
, a duplicate array element will be added to$this->_sortedChildren
.Then when we loop through the sorted children in
Mage_Core_Block_Text_List
, we will encounter the block nametest_a
twice, callgetBlock('test_a')
twice, and runtoHtml()
twice.https://github.com/OpenMage/magento-lts/blob/ca4f3217b7a0cb8d0b5b00df7c519922f55d99f3/app/code/core/Mage/Core/Block/Text/List.php#L27-L38
You could just not add duplicate block names, but it's actually useful if you want to override a block in a more specific handle without having to add
<action method="unsetChild">
.I also replaced
unset()
witharray_splice()
in theunsetChild
method. This seems like a better solution than the solution merged from PR #1108 which I reverted.Related Pull Requests
1108
Manual testing scenarios (*)
Add the following into your local.xml:
Results:
Questions or comments
I think I correctly replicated the issue in #1108, but if there's another test case please let me know. Ping @lemundo-team and @sreichel.
Contribution checklist (*)