diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index 85f97735e..dd49004db 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -141,7 +141,7 @@ public function compile(): string ->prepend( // Open the current scope sprintf( - '', + '', $this->dataAttributes->isNotEmpty() ? ', ' . $this->dataAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', $this->expressionAttributes->isNotEmpty() ? ', ' . $this->expressionAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', $this->scopedVariables->isNotEmpty() ? ', ' . $this->scopedVariables->map(fn (string $name) => "\${$name}")->implode(', ') : '', @@ -150,7 +150,7 @@ public function compile(): string ->append( // Close and call the current scope sprintf( - 'currentView?->data ?? []) %s %s) ?>', + 'currentView?->data ?? []) %s %s %s) ?>', ViewObjectExporter::export($this->viewComponentAttributes), ViewObjectExporter::export($slots), $this->scopedVariables->isNotEmpty() @@ -162,6 +162,9 @@ public function compile(): string $this->expressionAttributes->isNotEmpty() ? ', ' . $this->expressionAttributes->map(fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ') : '', + $this->scopedVariables->isNotEmpty() + ? ', ' . $this->scopedVariables->map(fn (string $name) => "{$name}: \${$name}")->implode(', ') + : '', ), ); diff --git a/packages/view/src/Parser/TempestViewParser.php b/packages/view/src/Parser/TempestViewParser.php index af0452aeb..77309107b 100644 --- a/packages/view/src/Parser/TempestViewParser.php +++ b/packages/view/src/Parser/TempestViewParser.php @@ -9,7 +9,7 @@ final class TempestViewParser private array $scope = []; private ?Token $currentScope { - get => $this->scope[array_key_last($this->scope) ?? ''] ?? null; + get => array_last($this->scope); } public function __construct( diff --git a/packages/view/src/Parser/TokenCollection.php b/packages/view/src/Parser/TokenCollection.php index a571fb396..b2f63a95a 100644 --- a/packages/view/src/Parser/TokenCollection.php +++ b/packages/view/src/Parser/TokenCollection.php @@ -40,7 +40,7 @@ public function __debugInfo(): array public function offsetExists(mixed $offset): bool { - return $this->tokens[$offset] ?? false; + return isset($this->tokens[$offset]); } public function offsetGet(mixed $offset): mixed diff --git a/packages/view/src/Renderers/TempestViewRenderer.php b/packages/view/src/Renderers/TempestViewRenderer.php index dcd259dac..e9665b879 100644 --- a/packages/view/src/Renderers/TempestViewRenderer.php +++ b/packages/view/src/Renderers/TempestViewRenderer.php @@ -135,7 +135,11 @@ public function escape(null|string|HtmlString|Stringable $value): string return (string) $value; } - return htmlentities((string) $value); + return htmlentities( + string: (string) $value, + flags: ENT_QUOTES | ENT_SUBSTITUTE, + encoding: 'UTF-8', + ); } private function validateView(View $view): void diff --git a/packages/view/src/Slot.php b/packages/view/src/Slot.php index 86a5b0b8b..d0e086cd6 100644 --- a/packages/view/src/Slot.php +++ b/packages/view/src/Slot.php @@ -22,7 +22,7 @@ public function __construct( } public string $content { - get => base64_decode($this->content, true); + get => base64_decode($this->content, strict: true) ?: ''; } public ImmutableArray $exportData {