Review main Merged Breaking

26784[!!!][BUGFIX] Cast negative int to boolean (true) in BooleanNode

Alexander Schnitzler CR +2 V +2 Easy +41 −6 updated 03/22/14, 17:01

Commit message

Currently Fluid treats negative integers as false which
results in <f:if condition="-9"> rendering else instead
of then.

When casting integers to boolean using php all integers
other than 0 (zero) are casted to true, just 0 results in
false. Therefore, casting of BooleanNode::convertToBoolean
must be adjusted to act like plain php.

This bugfix is a breaking change as people might have
deliberately used the wrong behaviour.

Review

  • Code review CR +2
    • Nicole Hummel +2
    • Stefan Neufeind +1
    • Oliver Hader +1
  • Verified V +2
    • Nicole Hummel +2
    • Oliver Hader +1

Issues 2

Files 2

Review log 48

Show 23 earlier messages
  1. Oliver Klee commented on patch set 1 01/13/14, 14:09

    BooleanNode.php:323

    int-> integer (to be consistent with Jo's changes)
  2. Alexander Schnitzler uploaded patch set 2 01/13/14, 14:15

  3. Mr. Jenkins commented on patch set 1 01/13/14, 14:15

  4. Oliver Klee voted on patch set 2 CR +1 01/13/14, 14:19

  5. Alexander Schnitzler commented on patch set 2 01/13/14, 14:20

  6. Mr. Jenkins commented on patch set 2 01/13/14, 14:27

  7. Bastian Waidelich commented on patch set 2 01/13/14, 14:31

    BooleanNode.php:322

    Why the ctype-check? wouldn't:: if (is_numeric($value)) { return (integer)$value !== 0; } suffice?
  8. Alexander Schnitzler voted on patch set 2 CR -2 01/13/14, 14:51

  9. Oliver Klee commented on patch set 2 01/13/14, 15:06

    BooleanNode.php:322 Reply

    That depends on whether values like 0.5 or -0.5 should be TRUE or FALSE.
  10. Ingo Pfennigstorf commented on patch set 2 V -1 CR -1 01/13/14, 15:10

    a ctype check was removed in #43726 because not all the "enterprise lts" distributions offer packages for it ...

    BooleanNode.php:322

  11. Markus Klein commented on patch set 2 01/13/14, 15:31

    IMHO this should go down to 4.5 then to have a stable API. Extensions should work on all versions.
  12. Alexander Schnitzler uploaded patch set 3 01/13/14, 15:56

  13. Alexander Schnitzler voted on patch set 3 CR 0 01/13/14, 15:56

  14. Alexander Schnitzler commented on patch set 2 01/13/14, 16:01

    Reply

    Agree with you but let's find a proper solution first. :)
  15. Oliver Klee voted on patch set 3 CR +1 01/13/14, 16:05

  16. Mr. Jenkins commented on patch set 3 CR -1 V -1 01/13/14, 16:08

  17. Alexander Schnitzler commented on patch set 3 CR -2 01/13/14, 16:09

    Damn, PHP 5.3 again. Cannot handle the binary notation 0b01.
  18. Oliver Klee voted on patch set 3 CR 0 01/13/14, 16:09

  19. Alexander Schnitzler uploaded patch set 4 01/13/14, 16:13

  20. Markus Klein updated the commit message in patch set 4 01/13/14, 16:22

  21. Mr. Jenkins commented on patch set 4 01/13/14, 16:28

  22. Mr. Jenkins commented on patch set 5 01/13/14, 16:37

  23. Alexander Schnitzler commented on patch set 5 01/13/14, 17:07

    @Markus: I do not agree on the release versions. Why can't you just stay put and talk to us just as I asked you? If we backported this issue, we would possibly change the behaviour of thousands of applications out there which is not acceptable. Therefore I firstly planned to introduce it to 6.2. So, please, if you do not have better arguments, revert the release versions and let's first talk to Ernesto.
  1. Markus Klein commented on patch set 5 01/13/14, 17:51

    @Alex: Sorry for that, but I'm a bit confused now, you wrote "Agree with you.." ?? Yes you said, you're looking for solutions, so I thought it would be ok to document this right in place, so it wouldn't be forgotten. (As it always is, when things are just written somewhere within the comments.) So I'm fine of course with reverting this back, I didn't want to spoil your efforts. Nevertheless, assuming this is 6.2 only, how would you write a Fluid template then in an extension which should be 4.5 and 6.2 compatible? Is there a simple solution for that?
  2. Markus Klein updated the commit message in patch set 5 01/13/14, 17:51

  3. Alexander Schnitzler commented on patch set 6 01/13/14, 18:03

    Hey Markus, first at all, thanks! Actually I don't even know if this is a change that should go into 6.2, I just added the Releases line. I don't have problems with you patching my patchsets, that's absolutely ok as this is open source software. But in the first place I am searching for the solution to the problem this patch is based on. I want to let Ernesto and the core devs decide if this should go into >= 6.2. I shouldn't have pushed this patchset for CMS, but for TYPO3.Fluid first, but I didn't really think about it when I typed "git push". Anyway, thanks for taking care and what do you think about the actual changes inside this patch?
  4. Mr. Jenkins commented on patch set 6 01/13/14, 18:08

  5. Markus Klein commented on patch set 6 01/13/14, 18:17

    Alex, I didn't realize that the line was just intended as a placeholder, I wouldn't have touched it, nor would I have read the commit message at all. ;-) I'd suggest to mark this as [WIP] then, would be clearer IMO. Regarding the code. It looks fine, but from a very naive perspective I'd ask why can't the method simply return (boolean)$value? This would exactly trigger the boolean evaluation process of PHP, which is intended here. (But I'm sure I'm missing an important detail here.) ;-)
  6. Bastian Waidelich commented on patch set 6 01/13/14, 18:27

    Thanks for the work! I won't vote this down, but for the record: I don't think that the current behavior should be changed for following reasons: Whether <f:if condition="{negativeNumber}"> should return TRUE is arguable but it returned FALSE for a long time now and changing that, introduces a breaking behavior that is really hard to detect (we all know that good change logs & release notes aren't a safe protection against this). I'm curious about other opinions

    BooleanNode.php:324

    We should measure the performance impact of using a regex here. And: Even though strings are value types, we shouldn't change the $value itself IMO
  7. Alexander Schnitzler commented on patch set 6 01/13/14, 18:32

    You are right about the WIP. Should have marked it that way. Sorry for that. I talked to Bastian a lot this afternoon about possible solutions, one of these is to just cast it to boolean. If we do so, plain integer and float values inside strings should be evaluated right, but we loose the ability to detect hexadecimal numbers. As for me I do not need this at all, I just want to let this issue be discussed by others. The main issue is, that negative numbers are currently casted to FALSE. If we have a little extra number detection or not isn't that important I guess.
  8. Markus Klein commented on patch set 6 01/13/14, 18:33

    Bastian: The exact same argument could be used the other way round, if one (like me) didn't know that condition="{negVal}" will not resolve to TRUE. Debugging this would be as hard. I actually tend to believe the (expected?) behaviour should be like it is in any other programming language. 0 means FALSE, any bitflip will be TRUE. But it is indeed a very tough problem here regarding backward compatibility. What about introducing a new attribute? Like <f:if test="">? would even be shorter to write...
  9. Bastian Waidelich commented on patch set 6 01/16/14, 14:01

    Hey Markus, thanks for your comments, I moved the discussion to the forge issue and added some prose: http://forge.typo3.org/issues/54243#note-14 ;) Regarding the additional "test" argument - I don't see how this could help with this issue!?
  10. Stefan Neufeind commented on patch set 6 01/16/14, 22:45

    BooleanNode.php:324 Reply

    +1 on both
  11. Stefan Neufeind commented on patch set 6 02/24/14, 23:23

    What do others think, maybe especially Ernesto?
  12. Oliver Hader commented on patch set 6 CR -1 03/21/14, 23:46

    BooleanNode.php:322

    I'm not sure whether I got that right... but wouln't "return $value != 0;" be enough for int, float and hexdec notations?
  13. Nicole Hummel uploaded patch set 7 03/22/14, 00:12

  14. Nicole Hummel voted on patch set 7 V +1 CR +1 03/22/14, 00:12

  15. Mr. Jenkins commented on patch set 7 03/22/14, 00:25

  16. Oliver Hader uploaded patch set 8 03/22/14, 00:53

  17. Oliver Hader commented on patch set 8 03/22/14, 00:54

    Use an implicit approach without RegEx
  18. Oliver Hader voted on patch set 8 V +1 CR +1 03/22/14, 00:55

  19. Mr. Jenkins commented on patch set 8 03/22/14, 01:07

  20. Stefan Neufeind voted on patch set 8 CR +1 03/22/14, 01:16

  21. Nicole Hummel voted on patch set 8 V +2 CR +2 03/22/14, 01:19

  22. Nicole Hummel merged patch set 9 03/22/14, 01:19

  23. Stefan Neufeind commented on patch set 9 03/22/14, 01:21

    no "forward-port" needed - Flow-Fluid does it completely different
  24. Helmut Hummel commented on patch set 9 03/22/14, 11:17

    Is this change pushed to Flow Fluid?
  25. Stefan Neufeind commented on patch set 9 03/22/14, 17:01

    please see my comment. Flow-Fluid has completely different source for this. We might imho either check ourselves or inform somebody of "them" that in the end hopefully both Fluids behave identically. But this is not something that we can port.