diff --git a/src/Stempler/src/Parser/Syntax/DynamicSyntax.php b/src/Stempler/src/Parser/Syntax/DynamicSyntax.php index 9863e91cc..5ecb17e47 100644 --- a/src/Stempler/src/Parser/Syntax/DynamicSyntax.php +++ b/src/Stempler/src/Parser/Syntax/DynamicSyntax.php @@ -80,9 +80,9 @@ private function fetchValues(string $body): array $src = new StringStream($body); while ($n = $src->peak()) { - if (\in_array($n, ['"', '"'])) { + if (\in_array($n, ['"', "'"], true)) { $values[\count($values) - 1] .= $n; - while ($nn = $src->peak()) { + while (($nn = $src->peak()) !== null) { $values[\count($values) - 1] .= $nn; if ($nn === $n) { break; diff --git a/src/Stempler/tests/Directive/DirectiveTest.php b/src/Stempler/tests/Directive/DirectiveTest.php new file mode 100644 index 000000000..6847f759c --- /dev/null +++ b/src/Stempler/tests/Directive/DirectiveTest.php @@ -0,0 +1,45 @@ +parse('@image("blog", "test.png", "150|250", "webp")'); + + $this->assertSame( + '', + $this->compile($doc), + ); + } + + public function testStringWithSingleQuotes(): void + { + $doc = $this->parse("@image('blog', 'test.png', '150|250', 'webp')"); + + $this->assertSame( + "", + $this->compile($doc), + ); + } + + public function testVariableInjection(): void + { + $doc = $this->parse('@image("blog", $src, "150|250", "webp")'); + + $this->assertSame( + '', + $this->compile($doc), + ); + } +} diff --git a/src/Stempler/tests/fixtures/ImageDirective.php b/src/Stempler/tests/fixtures/ImageDirective.php new file mode 100644 index 000000000..091a9e7e1 --- /dev/null +++ b/src/Stempler/tests/fixtures/ImageDirective.php @@ -0,0 +1,22 @@ +', + $directive->values[0], + \str_starts_with($directive->values[1], '$') ? \sprintf('""', $directive->values[1]) : $directive->values[1], + $directive->values[2], + $directive->values[3], + ); + } +}