Copy link to clipboard
Copied
Hi,
I encountered a very strange occurance where
- IsBoolean("123D") returned false
while
- IsBoolean("123D ") return true
The difference in the first and example is additional spaces in the 2nd example. One would expect both results to return false.
Can please explain why the 2nd example returns true? It is perplexing to me.
Coldfusion 9.0.1.
Copy link to clipboard
Copied
You should report it as a bug.
Copy link to clipboard
Copied
It's also broken in ColdFusion 10.
It's similar to this issue that I reported over a year ago:
isvalid("variableName") incorrectly validates strings with leading/trailing spaces or ending period
https://bugbase.adobe.com/index.cfm?event=bug&id=3631104
The isValid() bug is apparently fixed in the "next major release"... which I believe is translated that you'll need to purchase ColdFusion 11 (or possible 12) in order to for this bug to be "fixed".
Copy link to clipboard
Copied
This is a bug, but it is directly related to the "loose typing" of the CFML language. ColdFusion will cast numbers as booleans when appropriate (which is why you can do <cfif myQuery.Recordcount> or <cfif 14> ). ColdFusion will attempt to cast anything it can as a number, so the string "123D" is being interpreted as a decimal number. A similar thing happens with strings like "14E2" - ColdFusion interprets that as scientific notation and converts it into a number.
-Carl V.
Copy link to clipboard
Copied
@Carl
The curiosity is that ColdFusion sees "0d", "1d", "12d", etc. as non-boolean, and "0d ", "1d ", "12d ", etc. as boolean
Copy link to clipboard
Copied
BKBK That is weird. I didn't catch that. I would have expected the opposite behavior.
Copy link to clipboard
Copied
Another step to view all case with 3 characters:
https://trycf.com/gist/b9937bf15fb4fa9177c1b73c528a44f9/acf11?theme=monokai
"1D " e "1F " stands for "double" and "float" ?!?
Copy link to clipboard
Copied
There seems to be some disconnect with these functions. IsBoolean() is supposed to be a shortcut for isValid("boolean"). Using ColdFusion2016, isValid("boolean") returns "true" for both values whereas isBoolean() returns "false". I believe this is because isValid() performs a "right trim" prior to performing the test.
I reviewed previous responses and it appears I indicated in 2014 that Adobe was fixing the "trim-before-evaluate" bug. The report indicated that it's "fixed", but they fixed this only for "variablename" tests.
https://tracker.adobe.com/#/view/CF-3631104
The test string "123#CHR(32)##CHR(32)#" should not not evaluate to a valid boolean string. (Adding prefixed spaces to strings returns "false". Trailing spaces are trimmed.)
Copy link to clipboard
Copied
Might I suggest filing a new bug with reproducible examples?
Copy link to clipboard
Copied
Some third-party jQuery libraries I use provide unit tests so you can easily verify things work as they should. Are there any third-party resources for ColdFusion/Lucee that do this based on built-in functions? I've created some specific tests to troubleshooting issues when either a jQuery library, SQL or a client indicates that a value is valid/invalid and ColdFusion gets it wrong.
As for reproducible examples, the subject of this forum post should be example enough. I'll add some notes to existing bug reports w/a link back to this post as all issues are related to the same isValid() function that hasn't been fully fixed.
Copy link to clipboard
Copied
I still think you should submit a fresh bug report, focused on just the issues you identified above. Mixing additional issues as comments on existing bugs usually doesn't work well with the ColdFusion team.
As far as unit tests, I'd hope Adobe has some - but they never share them.