Fascinating cftry/cfcatch/cfoutput bug with ColdFusion

This was reported to me by Brian Paulson and I have to admit I was pretty surprised when I saw it. Consider the following code block:

<cfoutput>
	<cftry>
	<cfset cdata ="Test">
	<cfdump var="#variables#">
	#outputTest("test",{"cdata"=cdata})#
	
	<cfcatch type="any">
	    <cfdump var="#cfcatch#">
	</cfcatch>
	</cftry>
</cfoutput>

<cffunction name="outputTest" output="false">
    <cfargument name="id" type="string" default="">
    <cfargument name="options" type="struct">
    <!--- dont need to do anything in here --->
    <cfreturn id>
</cffunction>

Right away you may think, that cfoutput should be inside the cftry, and you’re right, but it doesn’t have to be, except for the fact that when you run this code, you get: Variable CDATA is not defined. Since CDATA has special meaning in XML, I thought perhaps it was a bug with ColdFusion’s parser, but renaming it doesn’t help. Note the cfdump of variables there. If I remove the outputTest UDF call I clearly see CDATA as a variable. In the UDF call I tried variables.cdata and it didn’t work. Using “variables” by itself though did work. I also tried making a new structure, s, with cdata as a value inside and then passed s to the UDF and that worked fine too.

The main issue seems to be the placement of the cfoutput. Moving them inside makes it work properly:

<cftry>
<cfoutput>
<cfset cdata ="Test">
#outputTest("test",{"cdata"=cdata})#
</cfoutput>
<cfcatch type="any">
    <cfdump var="#cfcatch#">
</cfcatch>
</cftry>

Brian filed a bug report for it you can view here: https://bugbase.adobe.com/index.cfm?event=bug&id=3989302. I tested it in Lucee and it works as expected.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate looking for his next gig. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments