Repository navigation
✨ New Features
- Extension::getAttributeContentTypes() – tell Latte that your custom attributes hold JavaScript, CSS or HTML, and it escapes them exactly like
onclick,styleorsrcdoc. Map names or prefixes, such as'x-on:*' => ContentType::JavaScriptfor Alpine or'data-tippy-content' => ContentType::Htmlfor Tippy, and it works in static values,name={$x}andn:attralike (#426) - Partial Function Application – on PHP 8.6, expressions in templates accept the placeholders
?and..., such asround(?, 2), also in the sandbox
⚠️ Behavior Changes
- srcdoc – trusted HTML passed as a plain string is now displayed as text (see Security). Wrap it in
Latte\Runtime\Htmlor use|noescape; anHtmlobject now keeps its tags. With migration warnings on, Latte reports every value whose output changes (#425) - A
nullURL attribute is omitted like any other attribute:<a href={$url}>withnullrenders nohrefinstead ofhref="". Migration warnings report it (#428) - URL attributes set by
n:attrare checked likehref={$url}(see Security); a trusted URL that must not be checked belongs tohref={$url|nocheck} n:tagand a dynamic tag name cannot turn an element into<textarea>or<title>, nor one of them into another element{include}of an HTML block or a text template intoonclickor another JavaScript attribute prints a JavaScript string, not code (see Security); write JavaScript directly into the attribute. Including text or HTML into astyleattribute throws, and so does{include}with|noescapeinside an HTML comment- Deprecated: a positional argument after a named one in
{include},{embed},{extends},{layout},{import}and{sandbox}, as PHP forbids such a call; it will be an error in the next minor version
🔒 Security
- The
srcdocattribute is escaped twice, as the browser decodes it twice, so<iframe srcdoc="<p>{$x}</p>">cannot smuggle in a<script>(#425) - Vue, petite-vue and AngularJS can no longer find a
{{formed by adjacent outputs such as{$a}{$b}, or printed from a variable inside<script type="text/template"> - An
Htmlobject, an HTML block or a value with|noescapeprinted into<textarea>or<title>can no longer end the element with</textarea>; it displays the same text as before n:attrchecks URL attributes such ashrefandsrc, so<a n:attr="href => $url">withjavascript:...is no longer an XSS- A variable printed in an HTML block or a text template that is included into
onclickorstylecan no longer run as JavaScript or inject CSS {include}with|noescapeescapes quotes in an attribute like{$x|noescape}, so a variable printed in the block can no longer end the attribute; insidesrcdoc,|noescapeencodes the trusted document once instead of only escaping quotes
🐛 Bug Fixes
- Braces in
<textarea>and<title>are printed as they are, so a value like{{ }}passes through a form unchanged (#409) - Blocks and includes in XML templates have the XML content type, so included text is converted by XML rules and including XML into XML works; mixing XML and HTML still works with a deprecation (#433)
|numberand|byteswith a locale round a half away from zero, the same as without one, and are much faster on repeated calls (#427)- Whitespace: the newline after an indented end tag such as
</ul>{/if}is kept, and the indentation of a line like{/block}</p>stays inside the block (#344) - Loading the same template from concurrent Swoole coroutines or fibers works (#404)
Thanks to @vrana for the attribute content types and the srcdoc, URL and XML escaping (#425, #426, #428, #433), and to @vosikar and @zipper for #427 and #424.