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

Commit 712c2b2

Browse files
committed
Merge branch 'hotfix/98' into develop
Forward port #98
2 parents f1e35d0 + e1d64b6 commit 712c2b2

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ All notable changes to this project will be documented in this file, in reverse
4040
and exception messages in the breadcrumbs and menu navigation helpers to
4141
remove references to 'module' keys for the `$partial` argument, as that key
4242
is no longer used.
43+
- [#98](https://github.com/zendframework/zend-view/pull/98) fixes how the
44+
`HeadMeta` helper renders the `<meta charset>` tag, ensuring it is the first
45+
rendered. As long as the `HeadMeta` helper is called early in your markup, this
46+
should ensure it is within the first 1024 characters, ensuring your document
47+
validates.
4348

4449
## 2.8.1 - 2016-06-30
4550

src/Helper/HeadMeta.php

+10-1
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

+15
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)