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

Commit dfcbbed

Browse files
committed
Merge branch 'samsonasik-fix-134'
2 parents 4d9954c + ed6cc45 commit dfcbbed

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/Helper/HeadMeta.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,22 +334,27 @@ protected function isValid($item)
334334
return false;
335335
}
336336

337+
$doctype = $this->view->plugin('doctype');
338+
if ($item->type === 'charset' && $doctype->isXhtml()) {
339+
return false;
340+
}
341+
337342
if (! isset($item->content)
338-
&& (! $this->view->plugin('doctype')->isHtml5()
339-
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))
343+
&& (! $doctype->isHtml5()
344+
|| (! $doctype->isHtml5() && $item->type !== 'charset'))
340345
) {
341346
return false;
342347
}
343348

344349
// <meta itemprop= ... /> is only supported with doctype html
345-
if (! $this->view->plugin('doctype')->isHtml5()
350+
if (! $doctype->isHtml5()
346351
&& $item->type === 'itemprop'
347352
) {
348353
return false;
349354
}
350355

351356
// <meta property= ... /> is only supported with doctype RDFa
352-
if (! $this->view->plugin('doctype')->isRdfa()
357+
if (! $doctype->isRdfa()
353358
&& $item->type === 'property'
354359
) {
355360
return false;
@@ -361,15 +366,15 @@ protected function isValid($item)
361366
/**
362367
* Append
363368
*
364-
* @param string $value
369+
* @param object $value
365370
* @return void
366371
* @throws Exception\InvalidArgumentException
367372
*/
368373
public function append($value)
369374
{
370375
if (! $this->isValid($value)) {
371376
throw new Exception\InvalidArgumentException(
372-
'Invalid value passed to append; please use appendMeta()'
377+
'Invalid value passed to append'
373378
);
374379
}
375380

@@ -414,15 +419,15 @@ public function offsetUnset($index)
414419
/**
415420
* Prepend
416421
*
417-
* @param string $value
422+
* @param object $value
418423
* @throws Exception\InvalidArgumentException
419424
* @return void
420425
*/
421426
public function prepend($value)
422427
{
423428
if (! $this->isValid($value)) {
424429
throw new Exception\InvalidArgumentException(
425-
'Invalid value passed to prepend; please use prependMeta()'
430+
'Invalid value passed to prepend'
426431
);
427432
}
428433

@@ -432,14 +437,14 @@ public function prepend($value)
432437
/**
433438
* Set
434439
*
435-
* @param string $value
440+
* @param object $value
436441
* @throws Exception\InvalidArgumentException
437442
* @return void
438443
*/
439444
public function set($value)
440445
{
441446
if (! $this->isValid($value)) {
442-
throw new Exception\InvalidArgumentException('Invalid value passed to set; please use setMeta()');
447+
throw new Exception\InvalidArgumentException('Invalid value passed to set');
443448
}
444449

445450
$container = $this->getContainer();
@@ -458,6 +463,7 @@ public function set($value)
458463
* Not valid in a non-HTML5 doctype
459464
*
460465
* @param string $charset
466+
* @param Exception\InvalidArgumentException
461467
* @return HeadMeta Provides a fluent interface
462468
*/
463469
public function setCharset($charset)
@@ -467,6 +473,11 @@ public function setCharset($charset)
467473
$item->charset = $charset;
468474
$item->content = null;
469475
$item->modifiers = [];
476+
477+
if (! $this->isValid($item)) {
478+
throw new Exception\InvalidArgumentException('XHTML* doctype has no attribute charset; please use appendHttpEquiv()');
479+
}
480+
470481
$this->set($item);
471482

472483
return $this;

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\InvalidArgumentException::class);
446+
$this->expectExceptionMessage('XHTML* doctype has no attribute charset; please use appendHttpEquiv()');
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)