Bug #90318
closedstdWrap.ifEmpty not called anymore on potentially empty strings
100%
Description
In https://review.typo3.org/c/Packages/TYPO3.CMS/+/58928 an optimization was introduced to avoid calling "ifEmpty" or "ifBlank" if the content is not empty. However this is wrongly evaluated for "ifEmpty".
Indeed "ifEmpty" bases itself on the PHP function "trim" which considers:
" " (ASCII 32 (0x20)), an ordinary space.
"\t" (ASCII 9 (0x09)), a tab.
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
"\0" (ASCII 0 (0x00)), the NUL-byte.
"\x0B" (ASCII 11 (0x0B)), a vertical tab.
as empty characters. But the check that was introduced about whether to call "ifEmpty" or not checks emptiness with the "empty" PHP function which considers:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
as empty elements. This is very different from "trim" (excerpts taken from the PHP manual).
I would say the proper check should be:
$functionName === 'ifEmpty' && trim($content) !== ''
Updated by Francois Suter almost 5 years ago
- Related to Bug #86969: stdWrap ifEmpty/ifNull/ifBlank are evaluated even if content is there added
Updated by Francois Suter almost 5 years ago
Instructions for testing. Add the following TS to your template:
page.5 = TEXT
page.5 {
value (
)
ifEmpty.override.cObject = TEXT
ifEmpty.override.cObject.value = EMPTY!
wrap = <p>|</p>
}
Without the patch, you will see a paragraph with a lot of empty spaces when looking at the HTML source. After the patch, the text "EMPTY!" appears.
Updated by Gerrit Code Review almost 5 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63175
Updated by Gerrit Code Review over 4 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63457
Updated by Anonymous over 4 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset a02784d7b52266652d7cf38b2348bed26bf40810.
Updated by Sascha Egerer over 4 years ago
- Related to Bug #90908: Zeros are not treated as empty values in `.ifEmpty` added
Updated by Helmut Hummel over 4 years ago
Francois Suter wrote:
Indeed "ifEmpty" bases itself on the PHP function "trim" which considers:
That assumption is different from what is documented:
Documentation says: "Zeros are treated as empty values!"
Which means, the changes applied with this change introduced a regression