Skip to main content
Inspiring
November 20, 2014
Question

IsBoolean() returning true for "123D ", but false for "123D"?

  • November 20, 2014
  • 4 replies
  • 1604 views

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.

    This topic has been closed for replies.

    4 replies

    Participant
    July 12, 2017

    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" ?!?

    James Moberg
    Inspiring
    July 12, 2017

    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.)

    Carl Von Stetten
    Legend
    July 18, 2017

    Might I suggest filing a new bug with reproducible examples?

    Carl Von Stetten
    Legend
    November 20, 2014

    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.

    BKBK
    Community Expert
    Community Expert
    November 20, 2014

    @Carl

    The curiosity is that ColdFusion sees "0d", "1d", "12d", etc. as non-boolean, and "0d ", "1d ", "12d ", etc. as boolean

    Carl Von Stetten
    Legend
    November 20, 2014

    BKBK That is weird. I didn't catch that. I would have expected the opposite behavior.

    James Moberg
    Inspiring
    November 20, 2014

    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".

    BKBK
    Community Expert
    Community Expert
    November 20, 2014

    You should report it as a bug.