Project

General

Profile

Actions

Bug #84434

closed

TypoScript ifBlank does not work with strlen like expected

Added by Stefan Froemken over 6 years ago. Updated over 6 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 1 (0 open1 closed)

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

Actions
Actions #1

Updated by Susanne Moog over 6 years ago

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

Actions #2

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

Actions #3

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.

Actions #4

Updated by Mathias Brodala over 6 years ago

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

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

Actions #6

Updated by Mathias Brodala over 6 years ago

  • Is Regression set to Yes
Actions #7

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

Actions #8

Updated by Stefan Froemken over 6 years ago

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

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)

Actions #10

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.

Actions #11

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?

Actions #12

Updated by Oliver Hader over 6 years ago

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

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>
Actions #15

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.

Actions #16

Updated by Simon Gilli over 6 years ago

Cool!

Actions

Also available in: Atom PDF