Probable bug in implementation of arrayContains()

34 views
Skip to first unread message

Adam Cameron

unread,
Aug 23, 2012, 7:38:27 AM8/23/12
to ra...@googlegroups.com
G'day
Consider this code:

<cfset st = {key="value"}>
<cfset a = [st]>
<cftry>
    <cfset b = arrayContains(a, st)>
    <cfcatch>
        <cfdump var="#cfcatch#">
    </cfcatch>
    <cffinally>
        <cfdump var="#variables#">
    </cffinally>
</cftry>

This errors with:

Railo 3.3.4.003 Error (expression)
MessageCan't cast Complex Object Type Struct to String
DetailUse Build-In-Function "serialize(Struct):String" to create a String from Struct

The problem seems to be this (from http://wiki.getrailo.org/wiki/3-1-Functions:ArrayContains):

Arguments


NameTypeRequiredPositionDefaultDescription
haystackArrayYes1

needleStringYes2
needle should not be a string, it should be anything (see http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS2EF4F7C2-F41D-42fe-940D-B7C0212FF3D9.html).

Also, to be completely equivalent to CF it should return a boolean, not a numeric (however I agree that CF's arrayContains() function returns a boolean is a bit daft).

I guess this could be legit if Railo's version of arrayContains() predates CF's?

--
Adam

Adam Cameron

unread,
Aug 23, 2012, 7:47:14 AM8/23/12
to ra...@googlegroups.com
NB: Same applies for arrayFind() / arrayFindNoCase() / arrayFindAll() / arrayFindAllNoCase().

--
Adam

Michael Offner

unread,
Aug 23, 2012, 8:27:58 AM8/23/12
to ra...@googlegroups.com
please first read my comment in this ticket

can you please open a ticket for the object instead of string as second parameter.

/micha

2012/8/23 Adam Cameron <adamcamero...@gmail.com>



--
/micha

Michael Offner CTO Railo Technologies GmbH

Adam Cameron

unread,
Aug 23, 2012, 9:01:49 AM8/23/12
to ra...@googlegroups.com


On Thursday, August 23, 2012 1:27:58 PM UTC+1, Michael Offner wrote:
please first read my comment in this ticket


I agree 100% with what you say here.

 
can you please open a ticket for the object instead of string as second parameter.



Done: https://issues.jboss.org/browse/RAILO-2045

NB: this was only for some demonstration code, so it does not impact me at all, so don't put any priority on this simply because I mentioned it.

I do mention this situation on my blog: http://adamcameroncoldfusion.blogspot.co.uk/2012/08/arrays-in-coldfusion-part-3.html.  So you might want to feedback there with what the standpoint is with Railo?  Up to you.  NB: I've found a number of other bugs too... I don't have time to raise them at the moment, but will do so this evening.

Cheers.

--
Adam

Michael Offner

unread,
Aug 23, 2012, 9:11:30 AM8/23/12
to ra...@googlegroups.com
tnx a lot for your input!

/micha

2012/8/23 Adam Cameron <adamcamero...@gmail.com>


Adam Cameron

unread,
Aug 24, 2012, 3:35:29 AM8/24/12
to ra...@googlegroups.com

 
can you please open a ticket for the object instead of string as second parameter.



Note there's some discussion on whether object-matches should only be considered for exactly the same object (as OpenBD kinda does), or equivalent objects (as CF does) should also match.  See thread here: https://groups.google.com/d/topic/openbd/hH-NP_UAXfI/discussion .

You might wanna consider that discussion if you decide to implement this ticket.

Cheers.

-- 
Adam

Michael Offner

unread,
Aug 24, 2012, 5:55:03 AM8/24/12
to ra...@googlegroups.com
after looking into this a little bit deeper i have seen why arraycontains second value only take strings as second parameter, the reason is very simple.
ArrayContains checks if the given string (second parameter) is a substring inside one of the elements in the array, for looking for objects you should use the function arrayFind. like written in prior thread, the ACF implementation of arrayContains makes no sense, because there is no benefit over arrayFind, so we decided not to follow acf here, also because we would brake compatibility to prior Railo versions.

/micha





 

2012/8/23 Adam Cameron <adamcamero...@gmail.com>
G'day
Reply all
Reply to author
Forward
0 new messages