Beware of Implicit Structs Bug in ColdFusion 9,0,1
This has been driving me nuts and I'm not sure how well documented this is, but I've stumbled across a bug in ColdFusion 9,0,1,274733 where implicit structs can end up as 'undefined' and crash your application.
I was working through an example from jQuery in Action, Second Edition (you know, because I was trying to figure something else out) when this happened to me again and I thought I would go ahead and share a simple way for others to test and let me know if it's happening to them.
Create a page called test.cfm and drop this code in it, point your browser to it and you'll probably see an error of 'Variable TERMS is undefined'.
<cfscript>
if ( not IsDefined('term') ) {
term = 'unknown';
};
term = lcase(term);
terms = {
'oil-tanned' = 'A method of leather tanning in which oils or fats are used to cure the leather. Such leather is usually very supple and has a matte or "oily" finish and is not generally polishable.',
'full-grain' = 'Leather which has not been altered beyond hair removal. Full-grain leather is the most genuine type of leather, as it retains all of the original texture and markings of the original hide.',
'vibram' = 'A brand of boot and shoe sole created by Vitale Bramani in the 1930s, orginally for climbing boots. They are easily identified by the distinctive yellow Vibram® octagon. The Vibram® brand is recognized worldwide as the leader in high performance soling products for outdoor, dress casual, and service footwear.',
'goodyear welt' = 'The Goodyear welt is a method of attaching the sole of a shoe to the upper that is hand-stitched and allows multiple sole replacements, extending the life of the footwear.',
'cambrelle' = ' A non-woven synthetic fabric used primarily as a lining for shoes, boots and slippers.',
'cordura' = 'A certified fabric from INVISTA used in a wide range of products from luggage and backpacks to boots, to military wear and performance apparel. Cordura® is resistant to abrasions, tears and scuffs.',
'gore-tex' = 'A water-proof and breathable fabric that offers superior insulating abilities in a light-weight fabric.',
'stitch-down' = 'A method of boot construction that helps seal the boot against dirt, mud, and water and maximizes flexibility.',
'unknown' = 'Unknown term.'
};
</cfscript>
<cfoutput>#terms[term]#</cfoutput>
The funny thing is, if I move the code at the top of the page below the implicit struct, the page loads fine! Here's some code that should work now:
<cfscript>
terms = {
'oil-tanned' = 'A method of leather tanning in which oils or fats are used to cure the leather. Such leather is usually very supple and has a matte or "oily" finish and is not generally polishable.',
'full-grain' = 'Leather which has not been altered beyond hair removal. Full-grain leather is the most genuine type of leather, as it retains all of the original texture and markings of the original hide.',
'vibram' = 'A brand of boot and shoe sole created by Vitale Bramani in the 1930s, orginally for climbing boots. They are easily identified by the distinctive yellow Vibram® octagon. The Vibram® brand is recognized worldwide as the leader in high performance soling products for outdoor, dress casual, and service footwear.',
'goodyear welt' = 'The Goodyear welt is a method of attaching the sole of a shoe to the upper that is hand-stitched and allows multiple sole replacements, extending the life of the footwear.',
'cambrelle' = ' A non-woven synthetic fabric used primarily as a lining for shoes, boots and slippers.',
'cordura' = 'A certified fabric from INVISTA used in a wide range of products from luggage and backpacks to boots, to military wear and performance apparel. Cordura® is resistant to abrasions, tears and scuffs.',
'gore-tex' = 'A water-proof and breathable fabric that offers superior insulating abilities in a light-weight fabric.',
'stitch-down' = 'A method of boot construction that helps seal the boot against dirt, mud, and water and maximizes flexibility.',
'unknown' = 'Unknown term.'
};
if ( not IsDefined('term') ) {
term = 'unknown';
};
term = lcase(term);
</cfscript>
<cfoutput>#terms[term]#</cfoutput>
If I'm doing something wrong, please don't hesitate to point it out to me. Thanks!