diff --git a/composer.json b/composer.json index 7d8ae3bdf..d9e1125ed 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "nette/utils": "to use filter |webalize" }, "conflict": { - "nette/application": "<2.4.1" + "nette/application": "<3.0" }, "autoload": { "classmap": ["src/"] @@ -37,7 +37,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "3.0-dev" } } } diff --git a/src/Latte/Engine.php b/src/Latte/Engine.php index eaef49454..37e652ae3 100644 --- a/src/Latte/Engine.php +++ b/src/Latte/Engine.php @@ -17,7 +17,7 @@ class Engine { use Strict; - public const VERSION = '2.5.2'; + public const VERSION = '3.0-dev'; /** Content types */ public const diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index 25e9d12db..e7c30641f 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -268,6 +268,9 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) return "\$this->checkBlockContentType($blockType, $fname);" . "\$this->blockQueue[$fname][] = [\$this, '{$node->data->func}'];"; } + + } elseif ($name[0] === '_') { + throw new CompileException("Block name '$name' must not start with an underscore."); } // static snippet/snippetArea diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index cdf184ef3..81e06afe1 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -316,7 +316,7 @@ public static function strip(FilterInfo $info, string $s): string * @param bool $strip stripping mode * @return string HTML */ - public static function spacelessHtml(string $s, int $phase = null, bool &$strip = true): string + public static function spacelessHtml(string $s, ?int $phase = null, bool &$strip = true): string { if ($phase & PHP_OUTPUT_HANDLER_START) { $s = ltrim($s); @@ -324,18 +324,25 @@ public static function spacelessHtml(string $s, int $phase = null, bool &$strip if ($phase & PHP_OUTPUT_HANDLER_FINAL) { $s = rtrim($s); } - return preg_replace_callback( + $return = (string) preg_replace_callback( // Other cases '#[ \t\r\n]+|<(/)?(textarea|pre|script)(?=\W)#si', - function ($m) use (&$strip) { + static function (array $m) use (&$strip): string { if (empty($m[2])) { - return $strip ? ' ' : $m[0]; - } else { - $strip = !empty($m[1]); - return $m[0]; + return (string) $strip ? ' ' : $m[0]; } + $strip = !empty($m[1]); + return (string) $m[0]; }, $s ); + $return = (string) preg_replace_callback( // ' : (string) $m[0]; + }, + $return + ); + return $return; } diff --git a/src/Latte/Runtime/ISnippetBridge.php b/src/Latte/Runtime/ISnippetBridge.php index 5829e758f..9c9f3358b 100644 --- a/src/Latte/Runtime/ISnippetBridge.php +++ b/src/Latte/Runtime/ISnippetBridge.php @@ -16,17 +16,17 @@ */ interface ISnippetBridge { - function isSnippetMode(); + function isSnippetMode(): bool; - function setSnippetMode($snippetMode); + function setSnippetMode(bool $snippetMode); - function needsRedraw($name); + function needsRedraw(string $name): bool; - function markRedrawn($name); + function markRedrawn(string $name): void; - function getHtmlId($name); + function getHtmlId(string $name): string; - function addSnippet($name, $content); + function addSnippet(string $name, string $content): void; - function renderChildren(); + function renderChildren(): void; } diff --git a/tests/Latte/BlockMacros.block5.phpt b/tests/Latte/BlockMacros.block5.phpt index 9c7311199..9bbc185d6 100644 --- a/tests/Latte/BlockMacros.block5.phpt +++ b/tests/Latte/BlockMacros.block5.phpt @@ -26,3 +26,7 @@ Assert::match( '
', $latte->renderToString('{block test}
{/block}', ['var' => 123]) ); + +Assert::exception(function () use ($latte) { + $latte->renderToString('{define _foobar}Hello{/define}'); +}, Latte\CompileException::class, "Block name '_foobar' must not start with an underscore."); diff --git a/tests/Latte/mocks/SnippetBridge.php b/tests/Latte/mocks/SnippetBridge.php index 1fced3731..7bf3fcb63 100644 --- a/tests/Latte/mocks/SnippetBridge.php +++ b/tests/Latte/mocks/SnippetBridge.php @@ -18,19 +18,19 @@ public function isSnippetMode(): bool } - public function setSnippetMode($snippetMode) + public function setSnippetMode(bool $snippetMode) { $this->snippetMode = $snippetMode; } - public function needsRedraw($name): bool + public function needsRedraw(string $name): bool { return $this->invalid === true || isset($this->invalid[$name]); } - public function markRedrawn($name): void + public function markRedrawn(string $name): void { if ($this->invalid !== true) { unset($this->invalid[$name]); @@ -38,13 +38,13 @@ public function markRedrawn($name): void } - public function getHtmlId($name): string + public function getHtmlId(string $name): string { return $name; } - public function addSnippet($name, $content): void + public function addSnippet(string $name, string $content): void { $this->payload[$name] = $content; }