Quantcast
Channel: ColdFusion
Viewing all articles
Browse latest Browse all 1091

type checking cannot be trusted

$
0
0

Type checking cannot be trusted.

Repro:

<cfscript>
function f1(numeric myNumeric) {
return min(myNumeric, 1);
}

function f2(numeric myNumeric) {
return myNumeric.min(1);
}
</cfscript>

<cfscript>
function f3(date myDate) {
return dateAadd(“d”, 1, myDate);
}

function f4(date myDate) {
return myDate.add(“d”, 1);
}
</cfscript>

I can break someone’s f2 by passing a date to the numeric argument. I can break someone’s f4 by passing a numeric to the date argument.

Look at f1 vs f2 and f3 vs f4. See the only difference is the use of BIF vs member functions.

If you want to use member functions on numeric or date arguments, you’re going to need to write extra code to verify that the numeric argument is numeric and the date argument is a date.

Thoughts??

Thanks!,
-Aaron


Viewing all articles
Browse latest Browse all 1091

Trending Articles