Skip to content

Commit dff166b

Browse files
authored
fix(view): hardcoded boolean attributes shouldn't be parsed (#952)
1 parent e6f04ee commit dff166b

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/Tempest/View/src/Attributes/BooleanAttribute.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public static function matches(Element $element, string $attributeName): bool
3939
return false;
4040
}
4141

42+
if (! str_starts_with($attributeName, ':')) {
43+
return false;
44+
}
45+
4246
$attributeName = ltrim($attributeName, ':');
4347

4448
$allowedElements = match ($attributeName) {

src/Tempest/View/src/Exceptions/ViewCompilationError.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class ViewCompilationError extends Exception
1212
{
13-
public function __construct(string $content, Throwable $previous)
13+
public function __construct(string $path, string $content, Throwable $previous)
1414
{
1515
$excerpt = str($content)
1616
->excerpt(
@@ -32,14 +32,16 @@ public function __construct(string $content, Throwable $previous)
3232
'%s
3333
%s
3434
%s
35+
3536
%s
3637
37-
Could not compile %s',
38+
In %s
39+
',
3840
str_repeat('-', strlen($previous->getMessage())),
3941
$previous->getMessage(),
4042
str_repeat('-', strlen($previous->getMessage())),
4143
$excerpt,
42-
$content,
44+
$path,
4345
);
4446

4547
parent::__construct(

src/Tempest/View/src/Renderers/TempestViewRenderer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ private function renderCompiled(View $_view, string $_path): string
9292
try {
9393
include $_path;
9494
} catch (Throwable $throwable) {
95-
throw new ViewCompilationError(content: file_get_contents($_path), previous: $throwable);
95+
throw new ViewCompilationError(
96+
path: $_path,
97+
content: file_get_contents($_path),
98+
previous: $throwable
99+
);
96100
}
97101

98102
$this->currentView = null;

tests/Integration/View/TempestViewRendererDataPassingTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ public function test_boolean_attributes(): void
261261
<option value="<?= $value ?>" :selected="$selected"><?= $name ?></option>
262262
HTML, value: 'value', selected: false, name: 'name'),
263263
);
264+
265+
$this->assertSame(
266+
'<textarea autofocus></textarea>',
267+
$this->render('<textarea autofocus></textarea>')
268+
);
264269
}
265270

266271
public function test_expression_attribute_in_raw_element(): void

0 commit comments

Comments
 (0)