ZF-2663: Set name in headMeta View Helper deletes previous entries



pre class="highlight"> [Test Script] <?php set_include_path('../zf-trunk/library'); require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); $view = new Zend_View; $view->headMeta()->setName('keywords', 'php application'); $view->headMeta()->appendHttpEquiv('pragma', 'no-cache'); $view->headMeta()->appendHttpEquiv('Cache-control', 'no-cache'); $view->headMeta()->setName('keywords', 'xavi'); ?>

echo htmlentities($view->headMeta()->setPostfix("\n")); 

[Expected Output]

[Actual Output]

(Run against: r7761 & r8026)

CG wrote: I was expecting the second call to setName() to only override the 'keywords' index/property. Is this simply a misunderstanding on Xavier's and my side or this this indeed a bug?

MO'P wrote: Bug. Please file an issue in JIRA with the above reproduce/expect/actual information so either Ralph or I can look into it.


Fixed in r8253.

Please check, if not completely fixed, then reopen.


Use case provided by CG works after r8253 fix, but this doesn't:


pre class="highlight">[Test Script] <?php set_include_path('/Users/cyphelf/Sites/ZendFramework/library'); require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); $view = new Zend_View; $view->headMeta()->setName('keywords', 'php application'); $view->headMeta()->setName('description', 'php application'); $view->headMeta()->appendHttpEquiv('pragma', 'no-cache'); $view->headMeta()->appendHttpEquiv('Cache-control', 'no-cache'); $view->headMeta()->setName('keywords', 'xavi'); ?>

echo $view->headMeta()->setPostfix("\n"); 

[Expected Output]

[Actual Output]

(Run against: r9647)

It's a fix:

--- Zend/View/Helper/HeadMeta.php  (revision 9498)
+++ Zend/View/Helper/HeadMeta.php   (working copy)
@@ -268,7 +268,7 @@
         $container = $this->getContainer();
         foreach ($container->getArrayCopy() as $index => $item) {
-            if ($item->type == $value->type) {
+            if ($item->type == $value->type && $item->name == $value->name) {

The fix posted by Wojciech Naruniec is close, but it only works for meta name entries.

This condition

if ($item->type == $value->type && $item->name == $value->name) {

should replaced with

if ($item->type == $value->type && $item->{$item->type) == $value->{$value->type}) {

Fixed in trunk in r10457 Fixed in 1.5 branch in r10458 Fixed in 1.6 branch in r10459