Interesting change with listToArray from ColdFusion 8 to 9

Sorry if I’m late in noticing this - but something odd has happened with listToArray. I was reviewing SVN commits at work today when I noticed a coworker checked in a file where he stated that he had to modify a listToArray call because of “some change” to listToArray in ColdFusion 9. Now - I knew that listToArray changed in CF9. The reference shows that the multiCharacterDelimiter argument was added in CF9. However, in both CF8 and 9, the 3rd argument, includeEmptyFields, defaults to false.

So, given the following string:

<cfset str = ", A , B , , , 0"> <cfset arr = listToArray(str)> <cfdump var="#arr#">

I'd expect an array with 3 items: A, B ,0. However, in ColdFusion 8, the array contains A, B, 2 empty elements, and 0. I then noticed something. The list items weren't empty - they had a space. Technically, that's content. Now practically I can see why it is treated as empty content, but this was a surprising change since - for the most part - Adobe treats backwards compatability as something close to the Prime Directive. Personally I think CF8 is doing the right thing.

I can say that when ignoreEmptyFields is set to true, both CF8 and 9 return the exact same array.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA