Status/Resolution/Reason: To Fix/Fixed/BugVerified
Reporter/Name(from Bugbase): David Valeo / ()
Created: 08/27/2018
Components: Language, Functions
Versions: 2016,11.0,2018
Failure Type: Data Corruption
Found In Build/Fixed In Build: tested and failing on CF11, CF2016 and CF2018 / 2018,0,0,312276
Priority/Frequency: Normal / All users will encounter
Locale/System: ALL / Windows 10 64 bit
Vote Count: 1
Problem Description: When accessing variables in nested closures coldfusion reads from and writes to said variables in an inconsistent manner.
Steps to Reproduce:
{code:java}
component {
function test( event, rc, prc ){
var testvar = 'a';
var dostuff = function(){
testvar = 'b';
var domorestuff = function(){
testvar = 'c';
writedump( testvar ); // b? so when setting the variable we lost our reference to the outer testvar variable but somehow we still have access to the old one for reading,
writedump( variables.testvar ); // if the above is true and CF lost its scope for setting then it created a new testvar variable in the variables scope and it should be set to 'c' which it is.
testvar &= 'c'; //which one is going to be updated here?
//this should result in one of 2 outcomes
//1. mysteryscope.testvar = 'b' and variables.testvar = 'cc'
//OR
//2. mysteryscope.testvar = 'bc' and variables.testvar = 'c'
writedump( testvar ); // still b, so variables.testvar must be 'cc' right?
writedump( variables.testvar ); // nope.. we get a mixed result, it read mysteryscope.testvar and appended 'c' but set variables.testvar.
writeOutput('<br>');
};
domorestuff();
};
dostuff();
abort;
}
}
{code}
Actual Result: It seems like CF is using a different order when traversing scopes for reading and writing variables in nested closures. As a result a new variable is created in the calling components variables scope (which also seems a unexpected) but is not accessed properly when reading the variable back out.
Expected Result: CF should traverse scopes in the same order when getting and setting variables in nested closures.
Any Workarounds: Unknown
Attachments:
Comments: