Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 6fa6287

Browse files
committed
Merge branch 'hotfix/98'
Close #98
2 parents 8a1f196 + e1d64b6 commit 6fa6287

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ All notable changes to this project will be documented in this file, in reverse
2222
and exception messages in the breadcrumbs and menu navigation helpers to
2323
remove references to 'module' keys for the `$partial` argument, as that key
2424
is no longer used.
25+
- [#98](https://github.com/zendframework/zend-view/pull/98) fixes how the
26+
`HeadMeta` helper renders the `<meta charset>` tag, ensuring it is the first
27+
rendered. As long as the `HeadMeta` helper is called early in your markup, this
28+
should ensure it is within the first 1024 characters, ensuring your document
29+
validates.
2530

2631
## 2.8.1 - 2016-06-30
2732

src/Helper/HeadMeta.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,18 @@ public function toString($indent = null)
176176
$items = [];
177177
$this->getContainer()->ksort();
178178

179+
$isHtml5 = $this->view->plugin('doctype')->isHtml5();
180+
179181
try {
180182
foreach ($this as $item) {
181-
$items[] = $this->itemToString($item);
183+
$content = $this->itemToString($item);
184+
185+
if ($isHtml5 && $item->type == 'charset') {
186+
array_unshift($items, $content);
187+
continue;
188+
}
189+
190+
$items[] = $content;
182191
}
183192
} catch (Exception\InvalidArgumentException $e) {
184193
trigger_error($e->getMessage(), E_USER_WARNING);

test/Helper/HeadMetaTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,21 @@ public function testCharset()
422422
);
423423
}
424424

425+
public function testCharsetPosition()
426+
{
427+
$view = new View();
428+
$view->plugin('doctype')->__invoke('HTML5');
429+
430+
$view->plugin('headMeta')
431+
->setProperty('description', 'foobar')
432+
->setCharset('utf-8');
433+
434+
$this->assertEquals(
435+
'<meta charset="utf-8">' . PHP_EOL
436+
. '<meta property="description" content="foobar">',
437+
$view->plugin('headMeta')->toString());
438+
}
439+
425440
/**
426441
* @group ZF-9743
427442
*/

0 commit comments

Comments
 (0)