Zend Framework

Set name in headMeta View Helper deletes previous entries

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.3
  • Fix Version/s: 1.5.3
  • Component/s: Zend_View
  • Labels:
    None
  • Fix Version Priority:
    Must Have

Description

[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'); 
?>
<pre>
<?php 
echo htmlentities($view->headMeta()->setPostfix("\n")); 

[Expected Output]
<meta name="keywords" content="xavi" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-control" content="no-cache" />

[Actual Output]
<meta name="keywords" content="xavi" />

(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.

Activity

Hide
Ralph Schindler added a comment -

Fixed in r8253.

Please check, if not completely fixed, then reopen.

-ralph

Show
Ralph Schindler added a comment - Fixed in r8253. Please check, if not completely fixed, then reopen. -ralph
Hide
Wojciech Naruniec added a comment -

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

[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'); 
?>
<pre>
<?php 
echo $view->headMeta()->setPostfix("\n"); 
?>

[Expected Output]
<meta name="keywords" content="xavi" />
<meta name="description" content="php application" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-control" content="no-cache" />

[Actual Output]
<meta http-equiv="pragma" content="no-cache" >
<meta http-equiv="Cache-control" content="no-cache" >
<meta name="keywords" content="xavi" >

(Run against: r9647)
Show
Wojciech Naruniec added a comment - Use case provided by CG works after r8253 fix, but this doesn't:
[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'); 
?>
<pre>
<?php 
echo $view->headMeta()->setPostfix("\n"); 
?>

[Expected Output]
<meta name="keywords" content="xavi" />
<meta name="description" content="php application" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-control" content="no-cache" />

[Actual Output]
<meta http-equiv="pragma" content="no-cache" >
<meta http-equiv="Cache-control" content="no-cache" >
<meta name="keywords" content="xavi" >

(Run against: r9647)
Hide
Wojciech Naruniec added a comment -

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) {
                 $this->offsetUnset($index);
             }
         }
Show
Wojciech Naruniec added a comment - 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) {
                 $this->offsetUnset($index);
             }
         }
Hide
Andrew Ballard added a comment -

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

This condition

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if ($item->type == $value->type && $item->name == $value->name) {

should replaced with

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if ($item->type == $value->type && $item->{$item->type) == $value->{$value->type}) {
Show
Andrew Ballard added a comment - The fix posted by Wojciech Naruniec is close, but it only works for meta name entries. This condition
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if ($item->type == $value->type && $item->name == $value->name) {
should replaced with
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if ($item->type == $value->type && $item->{$item->type) == $value->{$value->type}) {
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - Fixed in trunk in r10457 Fixed in 1.5 branch in r10458 Fixed in 1.6 branch in r10459

People

Vote (3)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
2h
Original Estimate - 2 hours
Remaining:
2h
Remaining Estimate - 2 hours
Logged:
Not Specified
Time Spent - Not Specified