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

Commit f81b55d

Browse files
committed
Merge branch 'master' of git://github.com/zendframework/zf2
12 parents 192d20c + d2649e3 + f0162d1 + 6f01416 + a2b3753 + 1786961 + 1b97191 + d157fcb + 4444c37 + 811122b + 3a2cf9b + eb2029b commit f81b55d

File tree

4 files changed

+87
-24
lines changed

4 files changed

+87
-24
lines changed

src/Helper/HeadScript.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
408408
$attrString = '';
409409
if (!empty($item->attributes)) {
410410
foreach ($item->attributes as $key => $value) {
411-
if (!$this->arbitraryAttributesAllowed()
412-
&& !in_array($key, $this->_optionalAttributes))
411+
if ((!$this->arbitraryAttributesAllowed() && !in_array($key, $this->_optionalAttributes))
412+
|| in_array($key, array('conditional', 'noescape')))
413413
{
414414
continue;
415415
}
@@ -420,10 +420,25 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
420420
}
421421
}
422422

423+
424+
$addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));
425+
423426
$type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
424427
$html = '<script type="' . $type . '"' . $attrString . '>';
425428
if (!empty($item->source)) {
426-
$html .= PHP_EOL . $indent . ' ' . $escapeStart . PHP_EOL . $item->source . $indent . ' ' . $escapeEnd . PHP_EOL . $indent;
429+
$html .= PHP_EOL ;
430+
431+
if ($addScriptEscape) {
432+
$html .= $indent . ' ' . $escapeStart . PHP_EOL;
433+
}
434+
435+
$html .= $indent . ' ' . $item->source;
436+
437+
if ($addScriptEscape) {
438+
$html .= $indent . ' ' . $escapeEnd . PHP_EOL;
439+
}
440+
441+
$html .= $indent;
427442
}
428443
$html .= '</script>';
429444

@@ -456,8 +471,9 @@ public function toString($indent = null)
456471
} else {
457472
$useCdata = $this->useCdata ? true : false;
458473
}
474+
459475
$escapeStart = ($useCdata) ? '//<![CDATA[' : '//<!--';
460-
$escapeEnd = ($useCdata) ? '//]]>' : '//-->';
476+
$escapeEnd = ($useCdata) ? '//]]>' : '//-->';
461477

462478
$items = array();
463479
$this->getContainer()->ksort();

src/Helper/Navigation/AbstractHelper.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,31 @@ public function getContainer()
192192
return $this->container;
193193
}
194194

195+
/**
196+
* Verifies container and eventually fetches it from service locator if it is a string
197+
*
198+
* @param \Zend\Navigation\AbstractContainer|string|null $container
199+
* @throws \Zend\View\Exception\InvalidArgumentException
200+
*/
195201
protected function parseContainer(&$container = null)
196202
{
197203
if (null === $container) {
198-
; // intentionally left blank
199-
} else if (is_string($container)) {
204+
return;
205+
}
206+
207+
if (is_string($container)) {
200208
if (!$this->getServiceLocator()) {
201209
throw new Exception\InvalidArgumentException(sprintf(
202-
'Attempted to set container with alias "%s" but no ServiceLocator wwas set',
210+
'Attempted to set container with alias "%s" but no ServiceLocator was set',
203211
$container
204212
));
205213
}
214+
206215
$container = $this->getServiceLocator()->get($container);
207-
} else if (!$container instanceof Navigation\AbstractContainer) {
216+
return;
217+
}
218+
219+
if (!$container instanceof Navigation\AbstractContainer) {
208220
throw new Exception\InvalidArgumentException(
209221
'Container must be a string alias or an instance of ' .
210222
'Zend\Navigation\AbstractContainer'
@@ -215,7 +227,7 @@ protected function parseContainer(&$container = null)
215227
/**
216228
* Sets the minimum depth a page must have to be included when rendering
217229
*
218-
* @param int $minDepth [optional] minimum depth. Default is null, which
230+
* @param int $minDepth [optional] minimum depth. Default is null, which
219231
* sets no minimum depth.
220232
* @return AbstractHelper fluent interface, returns self
221233
*/
@@ -245,7 +257,7 @@ public function getMinDepth()
245257
/**
246258
* Sets the maximum depth a page can have to be included when rendering
247259
*
248-
* @param int $maxDepth [optional] maximum depth. Default is null, which
260+
* @param int $maxDepth [optional] maximum depth. Default is null, which
249261
* sets no maximum depth.
250262
* @return AbstractHelper fluent interface, returns self
251263
*/
@@ -297,9 +309,9 @@ public function getIndent()
297309
*
298310
* Implements {@link HelperInterface::setTranslator()}.
299311
*
300-
* @param mixed $translator [optional] translator. Expects an object of
312+
* @param mixed $translator [optional] translator. Expects an object of
301313
* type {@link Translator\Adapter\AbstractAdapter}
302-
* or {@link Translator\Translator}, or null.
314+
* or {@link Translator\Translator}, or null.
303315
* Default is null, which sets no translator.
304316
* @return AbstractHelper fluent interface, returns self
305317
*/
@@ -363,7 +375,7 @@ public function getAcl()
363375
*
364376
* Implements {@link HelperInterface::setRole()}.
365377
*
366-
* @param mixed $role [optional] role to set. Expects a string, an
378+
* @param mixed $role [optional] role to set. Expects a string, an
367379
* instance of type {@link Acl\Role\RoleInterface}, or null. Default
368380
* is null, which will set no role.
369381
* @return AbstractHelper fluent interface, returns self
@@ -377,7 +389,7 @@ public function setRole($role = null)
377389
$this->role = $role;
378390
} else {
379391
throw new Exception\InvalidArgumentException(sprintf(
380-
'$role must be a string, null, or an instance of '
392+
'$role must be a string, null, or an instance of '
381393
. 'Zend\Acl\Role\RoleInterface; %s given',
382394
(is_object($role) ? get_class($role) : gettype($role))
383395
));
@@ -456,7 +468,7 @@ public function setRenderInvisible($renderInvisible = true)
456468
*
457469
* Implements {@link HelperInterface::setUseTranslator()}.
458470
*
459-
* @param bool $useTranslator [optional] whether translator should be used.
471+
* @param bool $useTranslator [optional] whether translator should be used.
460472
* Default is true.
461473
* @return AbstractHelper fluent interface, returns self
462474
*/
@@ -691,8 +703,8 @@ public function htmlify(AbstractPage $page)
691703
* will not be accepted if it is the descendant of a non-accepted page.
692704
*
693705
* @param AbstractPage $page page to check
694-
* @param bool $recursive [optional] if true, page will not be
695-
* accepted if it is the descendant of a
706+
* @param bool $recursive [optional] if true, page will not be
707+
* accepted if it is the descendant of a
696708
* page that is not accepted. Default is true.
697709
* @return bool whether page should be accepted
698710
*/
@@ -822,16 +834,16 @@ public static function setDefaultAcl(Acl\Acl $acl = null)
822834
* Sets default ACL role(s) to use when iterating pages if not explicitly
823835
* set later with {@link setRole()}
824836
*
825-
* @param mixed $role [optional] role to set. Expects null, string, or an
837+
* @param mixed $role [optional] role to set. Expects null, string, or an
826838
* instance of {@link Acl\Role\RoleInterface}. Default is null, which
827839
* sets no default role.
828840
* @return void
829841
* @throws Exception\InvalidArgumentException if role is invalid
830842
*/
831843
public static function setDefaultRole($role = null)
832844
{
833-
if (null === $role
834-
|| is_string($role)
845+
if (null === $role
846+
|| is_string($role)
835847
|| $role instanceof Acl\Role\RoleInterface
836848
) {
837849
self::$defaultRole = $role;

test/Helper/CurrencyTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function setUp()
6363
{
6464
$this->clearRegistry();
6565

66-
$this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
67-
Currency\Currency::setCache($this->_cache);
66+
$cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
67+
Currency\Currency::setCache($cache);
6868

6969
$this->helper = new Helper\Currency('de_AT');
7070
}
@@ -78,7 +78,6 @@ public function setUp()
7878
public function tearDown()
7979
{
8080
unset($this->helper);
81-
$this->_cache->clear(CacheAdapter::MATCH_ALL);
8281
$this->clearRegistry();
8382
}
8483

test/Helper/HeadScriptTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,41 @@ public function testContainerMaintainsCorrectOrderOfItems()
430430

431431
$this->assertEquals($expected, $test);
432432
}
433-
}
434433

434+
public function testConditionalWithAllowArbitraryAttributesDoesNotIncludeConditionalScript()
435+
{
436+
$this->helper->__invoke()->setAllowArbitraryAttributes(true);
437+
$this->helper->__invoke()->appendFile('/js/foo.js', 'text/javascript', array('conditional' => 'lt IE 7'));
438+
$test = $this->helper->__invoke()->toString();
439+
440+
$this->assertNotContains('conditional', $test);
441+
}
442+
443+
public function testNoEscapeWithAllowArbitraryAttributesDoesNotIncludeNoEscapeScript()
444+
{
445+
$this->helper->__invoke()->setAllowArbitraryAttributes(true);
446+
$this->helper->__invoke()->appendScript('// some script', 'text/javascript', array('noescape' => true));
447+
$test = $this->helper->__invoke()->toString();
448+
449+
$this->assertNotContains('noescape', $test);
450+
}
451+
452+
public function testNoEscapeDefaultsToFalse()
453+
{
454+
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array());
455+
$test = $this->helper->__invoke()->toString();
456+
457+
$this->assertContains('//<!--', $test);
458+
$this->assertContains('//-->', $test);
459+
}
460+
461+
public function testNoEscapeTrue()
462+
{
463+
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array('noescape' => true));
464+
$test = $this->helper->__invoke()->toString();
465+
466+
$this->assertNotContains('//<!--', $test);
467+
$this->assertNotContains('//-->', $test);
468+
}
469+
470+
}

0 commit comments

Comments
 (0)