Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bizarre bug with named arguments and implicit struct creation in function call

Here's a really bizarre bug I recently ran across in CF9. Anyone have a clue why it is occurring and if either I am doing something wrong, or there is a hotfix available. Look at the following code. We take a string, add an A, add a B, and then attempt to add a C... yet the result we get is "ababc". The expected result is "abc". The bug only occurs if you do a named argument AND an implicit struct in argument pass AND a &= operator in the function call. If any of those 3 cases is not there, the bug does not occur. Any ideas why?

<cffunction name="test">
    <cfargument name="widget">

    <cfset var locals = StructNew()>

    <cfreturn arguments.widget.value>
</cffunction>

<cfset return = "">
<cfset return &= "a">
<cfset return &= "b">
<cfset return &= test(widget = { value = "c" })>
<cfoutput>#return#</cfoutput>
like image 415
Nucleon Avatar asked Dec 13 '11 00:12

Nucleon


1 Answers

Well: you've kinda answered your own question here: it happens because it's a bug. Bugs happen. It's good you've taken the time to advise Adobe about it.

As for work arounds, these two variations work fine:

<cfset return = "">
<cfset return &= "a">
<cfset return &= "b">
<cfset st = { value = "c" }><!--- refactor where the struct is created --->
<cfset return &= test(widget = st)>
<cfoutput>#return#</cfoutput>

Or:

<cfset return = "">
<cfset return &= "a">
<cfset return &= "b">
<cfset temp = test(widget = { value = "c" })><!--- refactor where the function is called --->
<cfset return &= temp>
<cfoutput>#return#</cfoutput>

You're just gonna have to do something like that until Adobe gets around to fixing it :-(

like image 100
Adam Cameron Avatar answered Sep 23 '22 18:09

Adam Cameron