diff --git a/src/Helper/HeadScript.php b/src/Helper/HeadScript.php index 8987fe5e..45cbeb64 100644 --- a/src/Helper/HeadScript.php +++ b/src/Helper/HeadScript.php @@ -408,8 +408,8 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd) $attrString = ''; if (!empty($item->attributes)) { foreach ($item->attributes as $key => $value) { - if (!$this->arbitraryAttributesAllowed() - && !in_array($key, $this->_optionalAttributes)) + if ((!$this->arbitraryAttributesAllowed() && !in_array($key, $this->_optionalAttributes)) + || in_array($key, array('conditional', 'noescape'))) { continue; } @@ -420,10 +420,25 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd) } } + + $addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN)); + $type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type; $html = ''; @@ -456,8 +471,9 @@ public function toString($indent = null) } else { $useCdata = $this->useCdata ? true : false; } + $escapeStart = ($useCdata) ? '//' : '//-->'; + $escapeEnd = ($useCdata) ? '//]]>' : '//-->'; $items = array(); $this->getContainer()->ksort(); diff --git a/src/Helper/Navigation/AbstractHelper.php b/src/Helper/Navigation/AbstractHelper.php index 83f3f6f4..bacd3175 100644 --- a/src/Helper/Navigation/AbstractHelper.php +++ b/src/Helper/Navigation/AbstractHelper.php @@ -192,19 +192,31 @@ public function getContainer() return $this->container; } + /** + * Verifies container and eventually fetches it from service locator if it is a string + * + * @param \Zend\Navigation\AbstractContainer|string|null $container + * @throws \Zend\View\Exception\InvalidArgumentException + */ protected function parseContainer(&$container = null) { if (null === $container) { - ; // intentionally left blank - } else if (is_string($container)) { + return; + } + + if (is_string($container)) { if (!$this->getServiceLocator()) { throw new Exception\InvalidArgumentException(sprintf( - 'Attempted to set container with alias "%s" but no ServiceLocator wwas set', + 'Attempted to set container with alias "%s" but no ServiceLocator was set', $container )); } + $container = $this->getServiceLocator()->get($container); - } else if (!$container instanceof Navigation\AbstractContainer) { + return; + } + + if (!$container instanceof Navigation\AbstractContainer) { throw new Exception\InvalidArgumentException( 'Container must be a string alias or an instance of ' . 'Zend\Navigation\AbstractContainer' @@ -215,7 +227,7 @@ protected function parseContainer(&$container = null) /** * Sets the minimum depth a page must have to be included when rendering * - * @param int $minDepth [optional] minimum depth. Default is null, which + * @param int $minDepth [optional] minimum depth. Default is null, which * sets no minimum depth. * @return AbstractHelper fluent interface, returns self */ @@ -245,7 +257,7 @@ public function getMinDepth() /** * Sets the maximum depth a page can have to be included when rendering * - * @param int $maxDepth [optional] maximum depth. Default is null, which + * @param int $maxDepth [optional] maximum depth. Default is null, which * sets no maximum depth. * @return AbstractHelper fluent interface, returns self */ @@ -297,9 +309,9 @@ public function getIndent() * * Implements {@link HelperInterface::setTranslator()}. * - * @param mixed $translator [optional] translator. Expects an object of + * @param mixed $translator [optional] translator. Expects an object of * type {@link Translator\Adapter\AbstractAdapter} - * or {@link Translator\Translator}, or null. + * or {@link Translator\Translator}, or null. * Default is null, which sets no translator. * @return AbstractHelper fluent interface, returns self */ @@ -363,7 +375,7 @@ public function getAcl() * * Implements {@link HelperInterface::setRole()}. * - * @param mixed $role [optional] role to set. Expects a string, an + * @param mixed $role [optional] role to set. Expects a string, an * instance of type {@link Acl\Role\RoleInterface}, or null. Default * is null, which will set no role. * @return AbstractHelper fluent interface, returns self @@ -377,7 +389,7 @@ public function setRole($role = null) $this->role = $role; } else { throw new Exception\InvalidArgumentException(sprintf( - '$role must be a string, null, or an instance of ' + '$role must be a string, null, or an instance of ' . 'Zend\Acl\Role\RoleInterface; %s given', (is_object($role) ? get_class($role) : gettype($role)) )); @@ -456,7 +468,7 @@ public function setRenderInvisible($renderInvisible = true) * * Implements {@link HelperInterface::setUseTranslator()}. * - * @param bool $useTranslator [optional] whether translator should be used. + * @param bool $useTranslator [optional] whether translator should be used. * Default is true. * @return AbstractHelper fluent interface, returns self */ @@ -691,8 +703,8 @@ public function htmlify(AbstractPage $page) * will not be accepted if it is the descendant of a non-accepted page. * * @param AbstractPage $page page to check - * @param bool $recursive [optional] if true, page will not be - * accepted if it is the descendant of a + * @param bool $recursive [optional] if true, page will not be + * accepted if it is the descendant of a * page that is not accepted. Default is true. * @return bool whether page should be accepted */ @@ -822,7 +834,7 @@ public static function setDefaultAcl(Acl\Acl $acl = null) * Sets default ACL role(s) to use when iterating pages if not explicitly * set later with {@link setRole()} * - * @param mixed $role [optional] role to set. Expects null, string, or an + * @param mixed $role [optional] role to set. Expects null, string, or an * instance of {@link Acl\Role\RoleInterface}. Default is null, which * sets no default role. * @return void @@ -830,8 +842,8 @@ public static function setDefaultAcl(Acl\Acl $acl = null) */ public static function setDefaultRole($role = null) { - if (null === $role - || is_string($role) + if (null === $role + || is_string($role) || $role instanceof Acl\Role\RoleInterface ) { self::$defaultRole = $role; diff --git a/test/Helper/CurrencyTest.php b/test/Helper/CurrencyTest.php index 904a42c2..bfc2eddd 100644 --- a/test/Helper/CurrencyTest.php +++ b/test/Helper/CurrencyTest.php @@ -63,8 +63,8 @@ public function setUp() { $this->clearRegistry(); - $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0)); - Currency\Currency::setCache($this->_cache); + $cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0)); + Currency\Currency::setCache($cache); $this->helper = new Helper\Currency('de_AT'); } @@ -78,7 +78,6 @@ public function setUp() public function tearDown() { unset($this->helper); - $this->_cache->clear(CacheAdapter::MATCH_ALL); $this->clearRegistry(); } diff --git a/test/Helper/HeadScriptTest.php b/test/Helper/HeadScriptTest.php index 60c97d7b..2080b3ed 100644 --- a/test/Helper/HeadScriptTest.php +++ b/test/Helper/HeadScriptTest.php @@ -430,5 +430,41 @@ public function testContainerMaintainsCorrectOrderOfItems() $this->assertEquals($expected, $test); } -} + public function testConditionalWithAllowArbitraryAttributesDoesNotIncludeConditionalScript() + { + $this->helper->__invoke()->setAllowArbitraryAttributes(true); + $this->helper->__invoke()->appendFile('/js/foo.js', 'text/javascript', array('conditional' => 'lt IE 7')); + $test = $this->helper->__invoke()->toString(); + + $this->assertNotContains('conditional', $test); + } + + public function testNoEscapeWithAllowArbitraryAttributesDoesNotIncludeNoEscapeScript() + { + $this->helper->__invoke()->setAllowArbitraryAttributes(true); + $this->helper->__invoke()->appendScript('// some script', 'text/javascript', array('noescape' => true)); + $test = $this->helper->__invoke()->toString(); + + $this->assertNotContains('noescape', $test); + } + + public function testNoEscapeDefaultsToFalse() + { + $this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array()); + $test = $this->helper->__invoke()->toString(); + + $this->assertContains('//', $test); + } + + public function testNoEscapeTrue() + { + $this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array('noescape' => true)); + $test = $this->helper->__invoke()->toString(); + + $this->assertNotContains('//', $test); + } + +}