I encountered a very strange occurance where
- IsBoolean("123D") returned false
- 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.
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
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".
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.
The curiosity is that ColdFusion sees "0d", "1d", "12d", etc. as non-boolean, and "0d ", "1d ", "12d ", etc. as boolean
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.
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.)
Might I suggest filing a new bug with reproducible examples?
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.
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.