Bug #84434

TypoScript ifBlank does not work with strlen like expected

Added by Stefan Froemken over 3 years ago. Updated about 3 years ago.

Status:
Rejected
Priority:
Should have
Category:
TypoScript
Target version:
Start date:
2018-03-17
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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


Related issues

Related to TYPO3 Core - Task #54091: Use === operator instead of strlen() to check for zero length stringsClosed2013-11-29

Actions
#1

Updated by Susanne Moog over 3 years ago

I'd prefer to adjust the documentation in this case, as I consider spaces === blank.

#2

Updated by Gerrit Code Review over 3 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

#3

Updated by Stefan Froemken over 3 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.

#4

Updated by Mathias Brodala over 3 years ago

  • Related to Task #54091: Use === operator instead of strlen() to check for zero length strings added
#5

Updated by Gerrit Code Review over 3 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

#6

Updated by Mathias Brodala over 3 years ago

  • Is Regression set to Yes
#7

Updated by Gerrit Code Review over 3 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

#8

Updated by Stefan Froemken over 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#9

Updated by Oliver Hader about 3 years ago

  • Status changed from Resolved to New

The change has been reverted in #84520 again since it introduced a regression (see issue description)

#10

Updated by Simon Gilli about 3 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.

#11

Updated by Susanne Moog about 3 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?

#12

Updated by Oliver Hader about 3 years ago

  • Complexity deleted (no-brainer)
  • Is Regression deleted (Yes)
#14

Updated by Oliver Hader about 3 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>
#15

Updated by Oliver Hader about 3 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.

#16

Updated by Simon Gilli about 3 years ago

Cool!

Also available in: Atom PDF