Adobe ColdFusion Inconsistencies

I've run into a couple of ColdFusion quirks over the past few days that I thought I'd share. (I should note that these were observed on Adobe CF 8.)

SerializeJSON and Boolean Strings

If you try to serialize the strings "Yes","No","True" or "False" using SerializeJSON, ColdFusion will convert these strings to boolean values. (i.e. "Yes" becomes true, "False" becomes false). This is because ColdFusion is weakly typed and uses some pretty liberal implicit conversion rules when it comes to boolean evaluation. I see this as an issue for the purposes of searializing and deserializing JSON for two reasons. First, there is the potential to lose data. If you serialize the string "Yes" and then deserialize the JSON that ColdFusion generates you are left with true, which is obviously a totally different value than what you started with. Second, it is not really consistent behavior because SerialzeJSON does not convert 1 or 0 (also ColdFusion booleans) to the boolean values true and false. I think the better approach here would be to serialize all strings as strings and only serialize "real" boolean values as booleans.

IsXML()

The other inconsistency I ran into was with IsXML. If you pass something other than a string to IsXML the function throws an error. This is different than the documented behavior which states:

Returns

True, if the function parameter is a string that contains well-formed XML text; False, otherwise.

This is also different than the other CFML decision functions which simply return false if passed a function parameter they can't handle. (See IsXmlAttribute for example.)

I think the IsXML issue could definitely be consider a bug, and while the SerializeJSON issue is a little fuzzy, I've gone ahead and reported both as bugs.

Comments
radekg's Gravatar Still better than this one:

x = xmlParse("c:/windows/some_non_existing_file.xml")

This throws following error:
An error occured while Parsing an XML document.
Content is not allowed in prolog.

The only problem is what xmlParse is tryiing to parse is Java FileNotFound exception. This one just rocks in my opinion. It is there since CF7.
# Posted By radekg | 7/31/08 4:34 AM
Brad Wood's Gravatar It's kind of hokey, but if you add a space before or after the "yes" or "no", ColdFusion will leave it as a string when it serializes it.
# Posted By Brad Wood | 9/9/08 2:44 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.