A colleague says this: ```I found a difference in ...
# cfml-general
d
A colleague says this:
Copy code
I found a difference in CF2018 from CF9.
 
ListFind will not find a match in a list where the value starts or ends with a space.

CF9 : ListFind("A, B,C", "B") = true 
CF2018 : ListFind("A, B,C", "B") = false
(He doesn't really mean it returns true, just that it found the value in the list.) I thought listFind would only find exact matches, so leading or trailing spaces in either the find string or the list element that don't match would cause it not to be found, in every version. I don't have a cf9 server to verify that they used to be ignored. Does anyone? Or do you know about a change in this area?
j
I agree with your understanding. The "difference" looks like a bug fix to me.
I can't get CF 9 to work in CommandBox and trycf only goes back to CF 10. Looks like CF10 works the same as 2018.
So my guess is that the behavior was fixed between CF 9 and CF 10.
d
Either that or my colleague is misunderstanding something else about the code he's looking at, or the tests he thinks he ran :)
(cf9 needs a different java version, so it's harder to just whip up a server for it)
j
Ah ha! That makes sense. I've never tried before, but figured it was due to its ancientness.
t
yeah,
ListContains
would sort of look like it works that way... but it's because it's looking for a substring inside a list, instead of an item inside a list, not because it's ignoring spaces.
d
@Tim so listContains() is secretly just find(), and doesn't care about list delimiters or "list items" at all?
t
no, it's not quite that bad... I phrased it poorly. It's looking for a substring inside a list item. So if we do
ListContains("A, B,C", "B")
it returns
2
because it found
B
as part of the list item
B
, which is the second list item.
But
ListContains("A,Banana,C", "B")
would return the same thing.
d
Probably nobody cares, but just FYI, this morning I fired up my ancient laptop with old versions of CF, and on CF 9,0,2,282541, I got this:
listFind("A,B,C", "B")=2
listFind("A, B,C", "B")=0
listFind("A,B ,C", "B")=0
listFind("A,B,C", " B")=0
listFind("A,B,C", "B ")=0
Short version is that leading and trailing spaces in both list items and the item being searched for are significant, in that version of CF9. If they don't match, the item won't be found. That's what I expected. Whatever the issue is with the page my coworker was looking at, that isn't it, with the unlikely caveat that this behavior may have changed in a minor version I didn't test.