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

Commit b80a013

Browse files
committed
Fixes #134 : add Exception on HeadeMeta::setCharset() when the doctype is Xhtml
1 parent 4d9954c commit b80a013

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Helper/HeadMeta.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,15 @@ public function set($value)
458458
* Not valid in a non-HTML5 doctype
459459
*
460460
* @param string $charset
461+
* @throws Exception\RuntimeException
461462
* @return HeadMeta Provides a fluent interface
462463
*/
463464
public function setCharset($charset)
464465
{
466+
if ($this->view->plugin('doctype')->isXhtml()) {
467+
throw new Exception\RuntimeException('XHTML* doctype has no attribute charset');
468+
}
469+
465470
$item = new stdClass;
466471
$item->type = 'charset';
467472
$item->charset = $charset;

test/Helper/HeadMetaTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,18 @@ public function testCharsetPosition()
440440
);
441441
}
442442

443+
public function testCarsetWithXhtmlDoctypeGotException()
444+
{
445+
$this->expectException(Exception\RuntimeException::class);
446+
$this->expectExceptionMessage('XHTML* doctype has no attribute charset');
447+
448+
$view = new View();
449+
$view->plugin('doctype')->__invoke('XHTML1_RDFA');
450+
451+
$view->plugin('headMeta')
452+
->setCharset('utf-8');
453+
}
454+
443455
/**
444456
* @group ZF-9743
445457
*/

0 commit comments

Comments
 (0)