diff --git a/CHANGELOG b/CHANGELOG index 07baad014..f12eb289a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ # 3.30.1 (2026-XX-XX) * Speed up reading object attributes backed by getters or class constants + * Fix the sandbox not reporting the line of a rejected `guard` tag # 3.30.0 (2026-09-25) diff --git a/src/TokenParser/GuardTokenParser.php b/src/TokenParser/GuardTokenParser.php index eb4886579..7aba0f0d9 100644 --- a/src/TokenParser/GuardTokenParser.php +++ b/src/TokenParser/GuardTokenParser.php @@ -59,7 +59,7 @@ final class GuardTokenParser extends AbstractTokenParser } $stream->expect(Token::BLOCK_END_TYPE); - return new Nodes([$exists ? $body : $else]); + return new Nodes([$exists ? $body : $else], $token->getLine()); } public function decideGuardFork(Token $token): bool diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php index 3a975f116..2c50033dd 100644 --- a/tests/Extension/SandboxTest.php +++ b/tests/Extension/SandboxTest.php @@ -142,6 +142,7 @@ class SandboxTest extends TestCase yield ['flush', '{% flush %}']; yield ['for', '{% for i in 1..2 %}{% endfor %}']; yield ['from', '{% from "macros" import foo %}']; + yield ['guard', '{% guard function max %}{% endguard %}']; yield ['if', '{% if false %}{% endif %}']; yield ['import', '{% import "macros" as macros %}']; yield ['include', '{% include "macros" %}'];