[thelist] No Escape from ColdFusion

.jeff jeff at members.evolt.org
Mon Aug 27 14:21:24 CDT 2001


rory,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Rory.Plaire at wahchang.com
>
> Yea, just saw Raymond's next post. This would be a good
> UDF, looping through the fields of the structure and
> escaping the single quotes. I think I've wanted to
> investigate the intricacies of UDFs anyway...
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

actually, i wouldn't make a udf to apply the changes to an entire structure.
instead, i'd make a udf that applied the change to a single variable or
simple value key of a structure.  the reason for this is performance and
simplicity.

if you build it to apply the replace to all keys of a structure then you
have to also make sure to check that the value of the key is a simple value
and not a complex one like an array or another structure.  additionally,
you're looping through the structure a minimum of one time more than you
need to.  you're already looping for the query.  why not just do the replace
then?  also, if you loop over the structure in your function, are you sure
you want *all* key values to be escaped?

here's how i'd do it:

<cfscript>
  function DontEvenThinkAboutPreserveSingleQuotes(string)
  {
    return Replace(string, "'", "''", "ALL");
  }
</cfscript>

couldn't be simpler (except perhaps the name *grin*)

enjoy,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list