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

Commit 8fe98ad

Browse files
committed
Merge branch 'hotfix/21'
Close #21
2 parents 38d0a1f + 1b13a09 commit 8fe98ad

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#21](https://github.com/zendframework/zend-view/pull/21) updates the
22+
`headScript` helper to allow empty attribute types to render as keys only when
23+
using an HTML5 doctype.
2224

2325
## 2.6.7 - 2016-04-18
2426

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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ public function testConditionalScriptNoIE()
382382
{
383383
$this->helper->setAllowArbitraryAttributes(true);
384384
$this->helper->appendFile(
385-
'/js/foo.js', 'text/javascript', ['conditional' => '!IE']
385+
'/js/foo.js',
386+
'text/javascript',
387+
['conditional' => '!IE']
386388
);
387389
$test = $this->helper->toString();
388390

@@ -394,7 +396,9 @@ public function testConditionalScriptNoIEWidthSpace()
394396
{
395397
$this->helper->setAllowArbitraryAttributes(true);
396398
$this->helper->appendFile(
397-
'/js/foo.js', 'text/javascript', ['conditional' => '! IE']
399+
'/js/foo.js',
400+
'text/javascript',
401+
['conditional' => '! IE']
398402
);
399403
$test = $this->helper->toString();
400404

@@ -465,10 +469,26 @@ public function testNoEscapeTrue()
465469
public function testSupportsCrossOriginAttribute()
466470
{
467471
$this->helper->__invoke()->appendScript(
468-
'// some script' . PHP_EOL, 'text/javascript', ['crossorigin' => true]
472+
'// some script' . PHP_EOL,
473+
'text/javascript',
474+
['crossorigin' => true]
469475
);
470476
$test = $this->helper->__invoke()->toString();
471477

472478
$this->assertContains('crossorigin="', $test);
473479
}
480+
481+
/**
482+
* @group 21
483+
*/
484+
public function testOmitsTypeAttributeIfEmptyValueAndHtml5Doctype()
485+
{
486+
$view = new \Zend\View\Renderer\PhpRenderer();
487+
$view->plugin('doctype')->setDoctype(\Zend\View\Helper\Doctype::HTML5);
488+
$this->helper->setView($view);
489+
490+
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, '');
491+
$test = $this->helper->__invoke()->toString();
492+
$this->assertNotContains('type', $test);
493+
}
474494
}

0 commit comments

Comments
 (0)