Behaviour Change - Boolean True escaping to empty string
Version: Appears to be related to the many commits ~ September/3, I have not yet located the exact commit. Happy to investigate further if it would be helpful.
Bug Description
Boolean true appears to be evaluated to empty string, prior to ~ September 3 it would be evaluated to 1. Unsure if this is expected behaviour, but this change has introduced subtle bugs in existing templates.
Steps To Reproduce
{do $value = true}
<input value="{$value}">
<input value="{(string)$value}">
Output:
<input name="name" value="">
<input name="name" value="1">
Expected Behaviour
Prior to ~ 3/Sep/2025, this would output:
<input name="name" value="1">
<input name="name" value="1">
Possible Solution
Which version of Latte do you use? It seems to work as expected in versions 2.11.7, 3.0.23 and 3.1.x-dev
https://fiddle.nette.org/latte/#90db766dc5
The only change is in 3.1.x-dev in which autocast behavior is deprecated and warning Bool value in 'value' attribute is not supported. is triggered.
Considering the warning, perhaps an error handler that you use behaves incorrectly and causes the issue with the dev version of Latte.
Thanks for the feedback:
- I'm using master at latest commit 51e3c9b for development
- There is no custom error handler set
- Strict Typing/Parsing mode
I've investigated a bit further and the behaviour change starts at commit baf5e200170db14b7bedff78f3b147ed95dc524e:
Commit 9c26791666896fc8bcb6ffe6da7bea06f12f5d5b generates template:
echo ' <input value="';
echo LR\HtmlHelpers::escapeAttr($value) /* line 10:19 */;
echo '">
Commit baf5e200170db14b7bedff78f3b147ed95dc524e generates template:
echo ' <input ';
echo LR\HtmlHelpers::formatAttribute('value', $value) /* line 10:12 */;
echo '>
The formatAttribute helper can simply be changed to typecast bool as string as per float/int to replicate the previous behaviour, if that is desired, but that is up to you :)
@gtrbunny see this description https://forum.nette.org/en/36908-latte-3-1-a-revolution-in-attributes-that-will-make-your-life-easier
Thanks @dg! The changes look great, I will certainly take a look and do some testing. The migration warnings is much appreciated.