Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ survives regeneration.
| `bytes` | `Filters::bytes` | | |
| `capitalize` | `Filters::capitalize` | | needs ext-mbstring |
| `ceil` | `Filters::ceil` | | |
| `checkUrl` | `Filters::checkUrl` | | appended automatically to URL attributes by the `checkUrls` pass; opt out with `nocheck` |
| `checkUrl` | `Filters::checkUrl` | | appended automatically to URL attributes by the `checkUrls` pass as nullsafe `?\|checkUrl`, so null still drops the attribute; opt out with `nocheck` |
| `clamp` | `Filters::clamp` | | |
| `column` | `Filters::column` | | |
| `commas` | `Filters::commas` | | |
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Essential/Passes.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function checkUrlsPass(TemplateNode $node): void
&& !$node->modifier->removeFilter('nocheck') && !$node->modifier->removeFilter('noCheck')
&& !$node->modifier->hasFilter('datastream') && !$node->modifier->hasFilter('dataStream')
) {
$node->modifier->filters[] = new Php\FilterNode(new Php\IdentifierNode('checkUrl'));
$node->modifier->filters[] = new Php\FilterNode(new Php\IdentifierNode('checkUrl'), nullsafe: true); // null drops the attribute
}
});
}
Expand Down
6 changes: 6 additions & 0 deletions tests/common/Engine.migrationWarnings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Assert::error(
'Behavior change for attribute \'title\' with value null: previously it rendered as title="", now the attribute is omitted (on line 1 at column 17)',
);

Assert::error(
fn() => $latte->renderToString('<a href="{=null}">'),
E_USER_WARNING,
'Behavior change for attribute \'href\' with value null: previously it rendered as href="", now the attribute is omitted (on line 1 at column 12)',
);

Assert::error(
fn() => $latte->renderToString('<input onclick="{=foo}">'),
E_USER_WARNING,
Expand Down
9 changes: 8 additions & 1 deletion tests/common/Safe.url.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ Assert::match(


Assert::contains(
'LR\HtmlHelpers::formatAttribute(\' href\', ($this->filters->checkUrl)(($this->filters->upper)($url1)))',
'LR\HtmlHelpers::formatAttribute(\' href\', (($ʟ_tmp = ($this->filters->upper)($url1)) === null ? null : ($this->filters->checkUrl)($ʟ_tmp)))',
$latte->compile('<a href="{$url1|upper}"></a>'),
);


// null drops the attribute like in other attributes
Assert::match(
'<a></a> <img>',
$latte->renderToString('<a href={$url}></a> <img src="{$url}">', ['url' => null]),
);


// xlink:href in inline SVG
Assert::match(
'<svg><a xlink:href="">x</a></svg>',
Expand Down
Loading