CF9 PreserveSingleQuotes bug
This little bug comes courtesy of my boss at Contens. It appears that the function PreserveSingleQuotes() in Coldfusion 9 is unable to handle the results of a function that returns a string.
The Problem
You have a simple string, or list and wish to manipulate it, the results of the manipulation is then going to be used in a query so naturally you will want to use PreserveSingleQuotes() to make sure that your single quotes are not removed.Take the following simple example below:
<cfset mylist = "one,two,three,four">
<cfquery name="getStuff" datasource="#request.dsn#">
select * from mytable
where numbers in (#PreserveSingleQuotes(listQualify(mylist,"'"))#)
</cfquery>
Yes I could use cfqueryparam in this case, but for the sake of example lets pretend that I didn't. If you try this code or simply leave out the query and do the following:
<cfoutput>#PreserveSingleQuotes(listQualify(mylist,"'"))#</cfoutput>
ColdFusion 9 will throw an error:
Complex constructs are not supported with function PreserveSingleQuotes. Use simple variable instead.
Pardon me but a string or list is indeed a simple variable! PreserveSingleQuotes will also fail with the following:
<cfoutput>#preserveSingleQuotes(lCase("it's definitely a simple life!"))#</cfoutput>
Work Around
There is a work around to this ColdFusion 9 bug, simply store the results of the manipulation in a variable and then pass that variable to PreserveSingleQuotes() as I in the following snippet:<cfset mystring = lCase("it's definitely a simple life!")>
<cfoutput>#preserveSingleQuotes(mystring)#</cfoutput>
Just a heads up if you are migrating to CF9 or developing for both Railo and ColdFusion 9 to always test your code thoroughly in both environments.
Happy Coding...

Subscribe
Subscribe via RSS
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 jquery max2007 max2008 misc open source programming railo software technology ui
Recent Entries
No recent entries.
Blogroll
An Architect's View
CFSilence
Rey Bango
TalkingTree

I feel this is because of the Call By Reference.
ListQualify() returns one copy of the original list with qualifiers. That might be a complex object.
I am thinking so because - similar thing happening with structCopy() as well because of Call By Reference.
But Duplicate() is Call By Value.
http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbu...
-Adam
I'll track this one and ensure it gets into the 9.01 release (Sully).
-Adam
Most, I guess I cant say all, cf funtions can accept the results from another function as input so long as the function returns a datatype that is accepted.
I admit the signature for preservsingleQuote specifically states "PreserveSingleQuotes(variable)" and not PreserveSingleQuotes(string). So while you are technically correct this is, in my opinion, a shitty implementation.
I often resort to writing complex queries within a cfsavecontent (yes, with proper escaping), and then doing a cfquery with the saved query text afterwards, just so I can write the complex query in a straightforward way.
http://www.city32.com/www.startcooking.com/