tracker issue : CF-3954490

select a category, or use search below
(searches all categories and all time range)
Title:

Error handling implicit array in combination with ternary operator in <cfloop array="...">

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Markus Wiesner / Markus Wiesner (Markus Wiesner)

Created: 03/17/2015

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final / 292333

Priority/Frequency: Normal / Some users will encounter

Locale/System: English / Win 2008 Server R2 64 bit

Vote Count: 0

Listed in the version 2016.0.03.300466 Issues Fixed doc
Problem Description:
Defining an implicit array in combination with the ternary operator in a <cfloop array> results in a crash or missing output (depending on the condition result of the operator).

Steps to Reproduce:
<cfscript>
	str = "teststr";
	arr = ["testarr1","testarr2"];
	cond = "foo"; // crash
	// cond = "bar"; // no crash, but output is missing
</cfscript>
<ul>
<cfloop index="e" array="#(cond IS 'bar') ? arr : [str]#">
	<cfoutput><li>#HTMLEditFormat(e)#</li></cfoutput>
</cfloop>
</ul>
<ul>
<cfloop index="e" array="#(cond IS 'bar') ? arr : [str]#">
	<li><cfoutput>#HTMLEditFormat(e)#</cfoutput></li>
</cfloop>
</ul>

Actual Result:
Crash, if cond = "foo":
 Variable ___IMPLICITARRYSTRUCTVAR1 is undefined. 
in the first loop: <cfloop index="e" array="#(cond IS 'bar') ? arr : [str]#">

Missing <li> in second <ul>, if cond = "bar":
<ul>
<li>testarr1</li> <li>testarr2</li> 
</ul>
<ul>
testarr1</li>
testarr2</li>
</ul>

Expected Result:
With cond = "foo":
<ul>
<li>teststr</li> 
</ul>
<ul>
<li>teststr</li>
</ul>


With cond = "bar":
<ul>
<li>testarr1</li> <li>testarr2</li> 
</ul>
<ul>
<li>testarr1</li>
<li>testarr2</li>
</ul>

Any Workarounds:
Setting the array before <cfloop> works:
<cfset a = (cond IS 'bar') ? arr : [str]>
<cfloop index="e" array="#a#">
	<li><cfoutput>#HTMLEditFormat(e)#</cfoutput></li>
</cfloop>

Loop in <cfscript> works, too:
<ul>
<cfscript>
	for (e in ((cond IS 'foo') ? arr : [str])) {
		WriteOutput("<li>#HTMLEditFormat(e)#</li>");
	}
</cfscript>
</ul>

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3954490

External Customer Info:
External Company:  
External Customer Name: Markus
External Customer Email:  
External Test Config: ColdFusion Standard 10,0,15,283922 Windows 64-bit

Attachments:

Comments:

Forgot to mention that this still worked in ColdFusion 9.
Comment by External U.
8033 | March 17, 2015 06:35:50 AM GMT
Fixed in CF2016 . The fix will be available in next HF
Comment by Nitin K.
8034 | July 05, 2016 05:41:57 AM GMT