3

A ColdFusion server has been updated to ColdFusion 2018 (from ColdFusion 9 or 11).

One of the oldest applications on that server contains code like: < cfif arguments[key] NEQ "">

Before, this seems to have been equivalent to isDefined("arguments.key") or StructKeyExists(arguments, key).

Today, even though isDefined("arguments.key") is false, and StructKeyExists(arguments, key) is also negative, <cfif arguments[key] NEQ ""> fails, because arguments[key] doesn't behave like empty string anymore. In fact, < cfdump var="#arguments[key]#"> displays 'undefined'.

Is there anything I can do in order to avoid changing the code everywhere where empty string was used instead of StructKeyExists? Perhaps a ColdFusion server parameter? (THIS.enableNullSupport didn't help)

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
user13859151
  • 113
  • 6
  • 1
    Weird that it ever worked that way. As that same code would throw an error if used with a regular structure. (What was Adobe was thinking ....?) Anyway, I suspect there isn't a setting to change the behavior and that you'll need to update the code :/ – SOS Feb 27 '21 at 00:58
  • Check your code for `cfparam` that defaults these non-existent variables to empty strings (`default=""`). It could also be related to scope bleeding. It's hard to tell without seeing actual code, where you encounter the issue. – Alex Feb 27 '21 at 12:39
  • 1
    @Alex - The behavior of the arguments structure seems to be different than regular structures, and also seems to have changed around CF2018 https://trycf.com/gist/14effc106da7f5cabf6cbb48da8a4a17/acf11?theme=monokai – SOS Feb 28 '21 at 08:12
  • @SOS Yeah, you are right. I've written an answer for this. – Alex Feb 28 '21 at 19:45

2 Answers2

4

The bracket notation for the ARGUMENTS scope will always return an undefined value for non-existing keys and values in all versions of Adobe ColdFusion.

function f() {
    return arguments[key];
}
f(); // returns undefined

function f() {
    return arguments["key"];
}
f(); // returns undefined

function f() {
    return arguments.key;
}
f(); // throws exception: Element KEY is undefined in ARGUMENTS

All 3 cases should throw an exception. This is inconsistent and should be treated as a bug. It is probably only kept for backwards compatibility.

Anyway, as you already noticed:

// ACF 10
(undefined eq "") -> TRUE

// ACF 11
(undefined eq "") -> TRUE

// ACF 2016
(undefined eq "") -> TRUE

// ACF 2018
(undefined eq "") -> FALSE

// ACF 2021
(undefined eq "") -> TRUE

Adobe introduced NULL support in ACF 2018 and broke this behavior. They fixed it in ACF 2021, but not in ACF 2018, classic Adobe move.

Either report this bug to Adobe and hope for an update (last bugfixing for ACF 2018 was done in November 2019, so good luck) or fix your old application by not relying on this dodgy function argument check.

Alex
  • 7,743
  • 1
  • 18
  • 38
  • 1
    Great, thanks for all the details. Then, fixing the application it is. – user13859151 Mar 01 '21 at 09:39
  • @user13859151 - Out of curiosity, did you ever file a bug report for this, as it looks like the behavior has changed .. again ... as of CF2018 Update 11. – SOS Apr 26 '21 at 17:03
  • 1
    @SOS - no, I changed my code to make use of StructKeyExists instead – user13859151 Apr 28 '21 at 07:38
  • @user13859151 - Well that's a better solution IMO. Since the behavior seemed to have changed, I was just curious if they knowingly fixed the bug or it was just a happy side effect of some other update :-). – SOS Apr 29 '21 at 13:56
0

IsDefinedValue may help as it's agnostic to NULL and checks a value exists too.

https://cflib.org/udf/isDefinedValue

Harry
  • 11
  • 1