tracker issue : CF-4198540

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

Closure Passed as Argument

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Jake Churchill / Jake Churchill ()

Created: 04/19/2017

Components: Functions

Versions: 2016,2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2016.0.03.301771 / 2018.0.02.312567

Priority/Frequency: Major / All users will encounter

Locale/System: ALL / Windows 10 64 bit

Vote Count: 8

Problem Description:
 When passing a function closure to another function, if the argument type is string, the function is allowed to come through. I believe this to be incorrect

Steps to Reproduce:
 See attached CFML file

Actual Result:
 Passing a function closure to another function via an argument with type="string" allows the function to come through

Expected Result:
 "Argument XYZ passed to function ABC is not of type string" error message by server

Any Workarounds:
 None

 

Sample Code:
{code:java}<cffunction name="sayHello">
	<cfargument name="person" type="string" />
	<cfoutput>Hello, #ARGUMENTS.person#<br/></cfoutput>
</cffunction>
<cffunction name="testString">
	<cfargument name="arg1" type="string" />
	<cfdump var="#arguments#" label="arguments" expand="true" />
	<cfif NOT isSimpleValue(arguments.arg1)>
		<cfoutput>#Arguments.arg1("World")#<br/></cfoutput>
	</cfif>
</cffunction>
<cffunction name="testFunction">
	<cfargument name="arg1" type="function" />
	<cfdump var="#arguments#" label="arguments" expand="true" />
	<cfif NOT isSimpleValue(arguments.arg1)>
		<cfoutput>#Arguments.arg1("World")#<br/></cfoutput>
	</cfif>
</cffunction>

<cfoutput>
<strong>TESTS WITH FUNCTION</strong><br/>
I would expect this to fail based on argument type
<pre>testString(sayHello)</pre>result=
<cftry>
	<cfset testString(sayHello) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to succeed
<pre>testFunction(sayHello)</pre>result=
<cftry>
	<cfset testFunction(sayHello) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr><strong>TESTS WITH STRING</strong><br/>
I would expect this to succeed
<pre>testString('some string')</pre>result=
<cftry>
	<cfset testString('some string') />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to fail based on argument type
<pre>testFunction('some string')</pre>result=
<cftry>
	<cfset testFunction('some string') />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr><strong>TESTS WITH NUMBER</strong><br/>
I would expect this to succeed
<pre>testString(123)</pre>result=
<cftry>
	<cfset testString(123) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to fail based on argument type
<pre>testFunction(123)</pre>result=
<cftry>
	<cfset testFunction(123) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr><strong>TESTS WITH QUERY</strong><br/>
I would expect this to fail based on argument type
<pre>testString(QueryNew('id'))</pre>result=
<cftry>
	<cfset testString(QueryNew('id')) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to fail based on argument type
<pre>testString(QueryNew('id'))</pre>result=
<cftry>
	<cfset testFunction(QueryNew('id')) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr><strong>TESTS WITH STRUCT</strong><br/>
I would expect this to fail based on argument type
<pre>testString({})</pre>result=
<cftry>
	<cfset testString({}) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to fail based on argument type
<pre>testString({})</pre>result=
<cftry>
	<cfset testFunction({}) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr/><strong>TESTS WITH ARRAY</strong><br/>
I would expect this to fail based on argument type
<pre>testString([])</pre>result=
<cftry>
	<cfset testString([]) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
<hr width=20% align=left>I would expect this to fail based on argument type
<pre>testFunction([])</pre>result=
<cftry>
	<cfset testFunction([]) />
	<cfcatch>
		Error:#cfcatch.message#<br/>
	</cfcatch>
</cftry>
</cfoutput>

{code}

Attachments:

  1. April 19, 2017 00:00:00: closure.cfm

Comments:

I've run into strange bugs where a string was intended to be passed but it was a function and did not crash
Comment by Jason T.
913 | April 19, 2017 04:09:15 PM GMT
This may have be resolved with CF-4198335 / build 302165 - can the Adobe Team verify this?
Comment by Jason T.
914 | April 19, 2017 04:27:52 PM GMT
Checked on the latest build , does not work we need to fix this.
Comment by Suchika S.
915 | April 25, 2017 10:39:17 AM GMT