Saturday, 27 July 2013

toScript()? New to me. New bugs to me, too

G'day:
I'm in Portumna visiting my boy... well not right now, I'm in the pub starting my second pint of Guinness, but the point is I'm away from home and am on my baby netbook rather than my usual rig, so blogging / coding / internet access / my-ability-to-do-useful-things are all severely curtailed today.

That said, to kill time, I'm writing a coupla articles.

I am researching a "bug" on Railo, in that the toScript() function (not one I was familiar with. Docs: Railo | ColdFusion) doesn't preserve case of struct keys (/ object properties) when converting a CFML struct to a JS object. EG:

cfmlStruct = {
    unQuotedKeyName    = "yes",
    "quotedKeyName"    = true
};
jsCode = toScript(cfmlStruct, "jsObject");
writeDump([cfmlStruct, jsCode]);

This outputs:

Array
1
Struct
quotedKeyName
booleantrue
UNQUOTEDKEYNAME
stringyes
2
stringjsObject=new Object();jsObject["unquotedkeyname"]="yes";jsObject["quotedkeyname"]="true";

And Railo is just doing what ColdFusion does with this:

array
1
struct
UNQUOTEDKEYNAMEyes
quotedKeyNametrue
2jsObject = new Object(); jsObject["quotedkeyname"] = "true"; jsObject["unquotedkeyname"] = "yes";

There's a coupla interesting quirks here. Firstly CFML has always ignored the casing on struct keys when they're not quoted, and internally upper-cases them all. So it's a bit odd that it's decided to lower case them when converting to JS. However if a struct key is quoted when it's defined, the casing has always been preserved. Except note here that it's not being preserved when being converted to Javascript.

This has gotta be a bug, surely? I mean CFML is pretty liberal with casing (it only matters in query-of-query, I think?), but it allows for preserving the case of struct keys, and surely the people at Adobe are aware that Javascript is case-sensitive, so the sensible thing to to here is to preserve the case of whatever CF has??

Micha's commented on the original thread on the Railo Google group that Railo only behaves the way it does to mimic ColdFusion, but I'm not sure either should be behaving the way it does. Well Railo has a case because it's specifically copying ColdFusion. But ColdFusion's behaviour is daft, yes?

I think so. Bug raised: 3602705.

--
Adam