Coldfusion 9 ListToArray bug

Quite some time ago CONTENS made the decision to have our products work on both Coldfusion and Railo thereby providing our customers with an option. This does tend to increase our testing times but we feel it is important to give our customers the option. As most, if not all, of you know Coldfusion 9 was recently released. The customers we have that are on Coldfusion 9 naturally want to take advantage of the new features and improvements that have been announced in CF.

During one such test cycle we discovered a bug in Coldfusion 9's implementation of ListToArray(), this bug does not exist in CF8. The bug appears when using a specific type of list delimiter "{}". The following is an example you can try out for yourself.


<cfset lMyList = "{key1:value1}{key2:value2}">
<cfset test = ListLen(lMyList, "{}")>
<cfset test2 = listToArray(lMyList, "{}")>
<cfdump var="#test#">
<cfdump var="#test2#">
In Railo, and CF8 the code executes without problem, below is a screen shot of a dump from Railo:

Coldfusion 9 produces the following error message:

Illegal repetition {|}
The error occurred in D:\inetpub\wwwroot\cfstuff\listtoarray.cfm: line 5
3 : <cfset test = ListLen(lMyList, "{}")>
4 :
5 : <cfset test2 = listToArray(lMyList, "{}")>
6 :
7 :
ListLen() had no trouble with our unique delimiters, only listToArray choked on it.

Apparently this problem is only due to the curly braces, replacing the curly braces with "any" other character does not produce this problem. Why curly braces are being used I can't say but I believe this problem has something to do with the improvements in the implicit structures in CF9.

Happy Coding...

10 Comments to "Coldfusion 9 ListToArray bug"- Add Yours
Justin Carter's Gravatar That's a strange one indeed... it's just (supposed to be) a string - thats a crazy bug if ListToArray() is actually somehow internally trying to treat it as invalid syntax for an implicit struct?!
# Posted By Justin Carter | 11/5/09 3:08 AM
Sami Hoda's Gravatar Is there an Adobe Bug Number we can vote on?
# Posted By Sami Hoda | 11/5/09 6:13 AM
Leigh's Gravatar > only due to the curly braces

Interesting. The stack shows CF is using some sort of regex to do the split. So I guess it makes sense that "{}" would cause an error.
# Posted By Leigh | 11/5/09 8:14 AM
Gary Gilbert's Gravatar What bothers me the most is that CF8 and earlier versions don't have this problem.

Clearly a "feature", now we have to figure out, do we change our code or see if a fix comes out some how I think we can wait for a year before this gets looked at.
# Posted By Gary Gilbert | 11/6/09 5:34 PM
Adam Cameron's Gravatar I'd say this is very much an edge case.

Writing code that suggests "{key1:value1}{key2:value2}" is a list delimited with the "{}" characters is unlikely to crop up in well-thought-out code, because it only works in the first place due to the forgivingness of CF's list functions. specifying "{}" as a list delimiter says that EITHER "{" or "}" is a delimiter, and there's no sense of those characters being braces that might be paired, nor is there a sense that the delimiter is "{}" as opposed to two separate delimiters, nor - given your data - is it sensible to treat the data as a list delmited like that. What a shambles.

There's definitely a bug in CF there, I agree. But if you are writing code like this and actually being caught out by this bug, you're bringing it upon yourself for writing bad, illogical code. Basically it's garbage-in, garbage out.

Still: raise an E/R and I'll vote for getting it fixed. http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbu...#

--
Adam
# Posted By Adam Cameron | 11/6/09 7:49 PM
Dan Roberts's Gravatar Adam, It is a tool to split a string into an array and it has a bug. Did you wake up on the wrong side of the bed today?
# Posted By Dan Roberts | 11/6/09 4:29 AM
Gary's Gravatar @Adam

Not wanting to raise to the bait by your overly charged comment, but seriously without knowing where this is used and what specific reasons were chosen for the use of that delimiter I would be a little bit more careful with the garbage in garbage out comment. I can tell you that it was carefully chosen at the time the code was written for a specific use case. Whether it makes sense today is another story given the implicit structure and array declaration that now exists in CF.

Whatever a developer chooses to use as delimiter for a list is, in the end, completely irrelevant so long as he/she follows the rules stated in the documentation. That developer also has a certain expectation that upgrading won't break his code. That is the point of this article, not, in your opinion, the horrible choice of list delimiter.
# Posted By Gary | 11/7/09 6:25 PM
Adam Cameron's Gravatar Dan, Gary, sorry: my GIGO comment was a digression. I'm not sure digressions in a blog comment are really that rare or even necessarily inappropriate. I also don't think what I said was inaccurate at all: using braces like that to delimit a CF list is a contortion of the intent of CF lists. But never mind, we can disagree on that.

And note I *did* actually agree with your point that it's a bug, and I've voted for your E/R.

Cheers.

--
Adam
# Posted By Adam Cameron | 11/10/09 8:10 PM
Max Bergmann's Gravatar Hi,

There is another bug / different behavior between CF8 and CF9. Just to be aware Coldfusion9 ListToArray does not treat an element with a space in a list (e.g. "1, ,2" as an element in the array, but Coldfusion 8 does.

Have a look at this example:
   <cfset array = listToArray("element1, ,element2")>
   <cfdump var="#array#">

Coldfusion 9
array
1    element1
2    element2

Coldfusion 8:
array
1    element1
2   
3    element2
# Posted By Max Bergmann | 2/21/10 7:29 AM
# Posted By Rajesh Rajendran | 7/18/10 6:58 AM

Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.

Tags

adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List