Bug #84434
closedTypoScript ifBlank does not work with strlen like expected
100%
Description
Hello Core-Team,
in documentation you told us that ifBlank works with strlen to check, if a value is empty. OK, following example:
page.123 = TEXT page.123.value = blue, green, , red,,white page.123.preIfEmptyListNum = 2 page.123.ifBlank = pink
The value 2 between green and red are 2 spaces. So strlen will result in 2 which is not empty. But in Frontend you will see the value pink. So, something went wrong here.
In source code I saw that you are working with trim instead of strlen since TYPO3 7.
I will create a patch to correct that again.
Stefan
Updated by Susanne Moog over 6 years ago
I'd prefer to adjust the documentation in this case, as I consider spaces === blank.
Updated by Gerrit Code Review over 6 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/56305
Updated by Stefan Froemken over 6 years ago
Please use ifEmpty, if you want to consider spaces === blank. It is documented, that ifEmpty will trimm the values. That's the big difference between ifEmpty and ifBlank.
Updated by Mathias Brodala over 6 years ago
- Related to Task #54091: Use === operator instead of strlen() to check for zero length strings added
Updated by Gerrit Code Review over 6 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56305
Updated by Gerrit Code Review over 6 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56320
Updated by Stefan Froemken over 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset ac72c832b9d037c837a244b318984a6e1f4abd50.
Updated by Oliver Hader over 6 years ago
- Status changed from Resolved to New
The change has been reverted in #84520 again since it introduced a regression (see issue description)
Updated by Simon Gilli over 6 years ago
Stefan, I see you dilemma but documentation is correct here. It's mentioned both functions ifEmpty and ifBlank are trimming the value. So currently there seems not be a way for a such a case and you can't make a change without breaking current functionality.
fEmpty:
If the trimmed content is empty at this point, the content is loaded with "ifEmpty". Zeros are treated as empty values!
ifBlank:
Same as "ifEmpty" but the check is done using strlen().
My suggestion is providing a new function e.g. ifEmptyNoTrim or ifEmpty2.
Updated by Susanne Moog over 6 years ago
- Status changed from New to Needs Feedback
As far as I can see the code now follows the intention of the documentation - while the check is not checked with strlen (which should be removed / clarified in the docs) anymore it is still checked in the same way (typesafe against an empty string, so zero values are kept).
IMHO we don't need a code change here - and I don't see anything but constructed usecases for the "feature" of not trimming - do you have a real world use case for that?
Updated by Oliver Hader over 6 years ago
- Complexity deleted (
no-brainer) - Is Regression deleted (
Yes)
Updated by Simon Gilli over 6 years ago
I have made a PR to the documentation see https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-Typoscript/pull/148
Updated by Oliver Hader over 6 years ago
You can use this TypoScript to workaround the implementation using trim():
# Default PAGE object: page = PAGE page.123 = TEXT page.123.value = blue, green, , red,,white page.123.preIfEmptyListNum = 2 page.123.stdWrap.setContentToCurrent = 1 page.123.stdWrap.override = pink page.123.stdWrap.override { if.isFalse.current = 1 if.isFalse.replacement { 10 { search = /[\s0]/ replace = 1 useRegExp = 1 } } } page.123.wrap = <p>"|"</p> page.124 < page.123 page.124.value = blue, green, SOMETHING , red,,white page.125 < page.123 page.125.value = blue, green,0, red,,white page.126 < page.123 page.126.value = blue, green,, red,,white
Output is
<p>" "</p> <p>" SOMETHING "</p> <p>"0"</p> <p>"pink"</p>
Updated by Oliver Hader over 6 years ago
- Status changed from Needs Feedback to Rejected
- Priority changed from Must have to Should have
Closing since behavior of ifBlank
is like it should be and like it was in earlier versions as well.