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

Commit 4af74c7

Browse files
committed
Merge pull request #21 from matbech/patch-1
HeadScript: Handle empty type for HTML5
2 parents 38d0a1f + 1da5ac5 commit 4af74c7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Helper/HeadScript.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,12 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
400400
$addScriptEscape = !(isset($item->attributes['noescape'])
401401
&& filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));
402402

403-
$type = ($this->autoEscape) ? $this->escape($item->type) : $item->type;
404-
$html = '<script type="' . $type . '"' . $attrString . '>';
403+
if (empty($item->type) && $this->view && $this->view->plugin('doctype')->isHtml5()) {
404+
$html = '<script ' . $attrString . '>';
405+
} else {
406+
$type = ($this->autoEscape) ? $this->escape($item->type) : $item->type;
407+
$html = '<script type="' . $type . '"' . $attrString . '>';
408+
}
405409
if (!empty($item->source)) {
406410
$html .= PHP_EOL;
407411

test/Helper/HeadScriptTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,15 @@ public function testSupportsCrossOriginAttribute()
471471

472472
$this->assertContains('crossorigin="', $test);
473473
}
474+
475+
public function testOmitsTypeAttributeIfEmptyValue()
476+
{
477+
$view = new \Zend\View\Renderer\PhpRenderer();
478+
$view->plugin('doctype')->setDoctype(\Zend\View\Helper\Doctype::HTML5);
479+
$this->helper->setView($view);
480+
481+
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, '');
482+
$test = $this->helper->__invoke()->toString();
483+
$this->assertNotContains('type', $test);
484+
}
474485
}

0 commit comments

Comments
 (0)