tracker issue : CF-4199999

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

Cannot evaluate a string containing a function expression

| View in Tracker

Status/Resolution/Reason: To Fix//EnhancementRequired

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron ()

Created: 10/11/2017

Components: Language

Versions: 2016

Failure Type: Enhancement Request

Found In Build/Fixed In Build: 2016 /

Priority/Frequency: Normal / Very few users will encounter

Locale/System: / Platforms All

Vote Count: 2

This should work

myFunction = evaluate("function(){}");

it doesn't:

Invalid CFML construct found on line 1 at column 11.

ColdFusion was looking at the following text:

The error occurred in C:/apps/adobe/ColdFusion/2016/express/cfusion/wwwroot/CF2018/src/misc/evaluateFunctionExpressionRepro.cfm: line 2
1 : <cfscript>
2 : myFunction = evaluate("function(){}");
3 : writeDump(variables);
4 : </cfscript>

It's a contrived repro case of a more complex situation wherein it was legit to be evaluating the function expression as it had dynamic code in it (don't ask... I'm under NDA so I can't say anyhow ;-)



Will this be fixed? An anonymous function declaration is a valid expression and there's no reason it shouldn't be capable of being evaluated. Why doesn't the evaluate() function work on all valid CFML expressions? On a side note, JavaScript will NOT work with this: eval("function(){}"); But it will run this code: eval("f=function(){}");
Comment by Bradley W.
29272 | July 11, 2018 04:56:09 AM GMT
Brad that JS example raises a good point. JS - legitimately - is seeing that as a function *statement* not a function expression. I wonder if perhaps CF's gonna have the same problem. I note that if one uses unambiguous syntax in JS, it works fine: ``` f = eval("()=>{}"); ``` (This doesn't work in Lucee btw, although by rights I guess it should).
Comment by Adam C.
33275 | March 11, 2020 07:35:17 PM GMT
Yes, sadly Lucee uses a different (and smaller) expression parser for the evaluate() function which has been a huge pain point for the CommandBox REPL since it means things like member functions chained to a literal work generally in Lucee but not correctly in the REPL since it uses evaluate(). I have a handful of Lucee tickets in for this. I assume Adobe's issue is similar.
Comment by Bradley W.
33276 | March 11, 2020 07:42:17 PM GMT