ColdFusion RegEx White List Example

Posted by Quinn Madson | Posted in | Posted on 9:49 AM

0

I needed to build a function that would strip out characters in event information because, otherwise it would break a JSON feed. Here is what I used:


<cffunction name="jsonSafe" access="private">
<cfargument name="str" type="string" required="true">
<cfset newStr = reReplace(arguments.str, '[^[:alnum:][:space:]$=;.?!\\/&"''`():,\[\]{}_\-]', '_','all')>
<cfreturn newStr>
</cffunction>

Preserve epoch dates in Zimbra JSON via ColdFusion DeserializeJSON function

Posted by Quinn Madson | Posted in | Posted on 2:14 PM

0

The DeserializeJSON() function in ColdFusion converts an epoch date/time in JSON from something like: 1281364965000 to: 1.281364965E+012.


To prevent this from happening, you can use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{13})', '"\1"', 'ALL')>


Alternatively, to convert any number, 10 digits or more into a string to preserve the proper formatting, use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{10,})', '"\1"', 'ALL')>