Null, zero length strings should be falsey

Description

I humbly request that nulls and zero-length strings be considered false in a conditional. I work with a lot of spreadsheets, unfortunately, and cells are often left blank instead of using 0. Having to add more conditional logic to handle those is painful. Removing commas and converting ( number ) to -number is bad enough :/

Attachments

1
  • 29 Dec 2021, 06:17 pm

Activity

Show:

John Wilson 29 December 2021 at 19:10

Thanks, Brad.


The last time I tried enabling full null support, coldbox, or one of the core modules, broke and I haven’t tried it again since then.

Brad Wood 29 December 2021 at 18:58

The easy fix for being able to treat anything as a boolean is to run it through the val() function. It will turn an empty string or null into false (well, 0 actually). As far as changing the default meaning of truthy and falsey, I'd suggest any changes that are made should be done in the broader context of this ticket:

https://luceeserver.atlassian.net/browse/LDEV-449

Even though I created that ticket (which you can see, has a whirlwind of opinions) I don’t really care for either of the string options presented as both of them have backwards compatibility issues. This is because CFML already has a loose truthy behavior of strings that’s not the same as the other languages that ticket is copying. Today, I’d probably recommend a 3rd “string option” where ““ is falsely and leave the rest as described. With the existing yes/no/true/false/1/0 string behaviors in CFML, it’s just not possible to overload a behavior that would also accurately tell you if a string was empty or not along the same lines as the array/struct versions.

Zac Spitzer 29 December 2021 at 18:26

then enable full null support

Won't Fix

Details

Assignee

Reporter

Labels

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Priority

Created 29 December 2021 at 18:18
Updated 29 December 2021 at 19:10
Resolved 29 December 2021 at 19:06

Flag notifications