CFLib.org – Common Function Library Project

fixURLDecode(string)

Last updated September 23, 2004

author

Anthony Petruzzi

Version: 1 | Requires: CF5 | Library: StrLib

Description:
There exists a problem in all versions of ColdFusion when you try to urldecode a string that contain a lone "%" such as "5% credit card". Usually the "%" will translate to "%25" if URLEncoded. However sometimes when programming you might not scope a variable so that you can get the value from either the URL or a FORM post. The problem is that if you get the variable from a FORM post, the string is not URLEncoded, this is where the bug comes into effect. In CF5 and below the uncoded "%" in the string will be returned as a blank, such as "5 credit card". However in CFMX this will cause an exception error. This UDF is a workaround for both CF5 and CFMX until a hotfix is available.

Return Values:
Returns a string.

Example:

<cfset variables.string = "5% credit card">
<cfoutput>#FixURLDecode(variables.string)#</cfoutput>

Parameters:

Name Description Required
string String to url decode. Yes

Full UDF Source:

/**
 * This is a workaround for the URLDecode bug that exists in CF5 and CFMX.
 * 
 * @param string      String to url decode. (Required)
 * @return Returns a string. 
 * @author Anthony Petruzzi (tonyp@rolist.com) 
 * @version 1, September 23, 2004 
 */
function fixURLDecode(string){
    return URLDecode(ReReplaceNoCase(string, "%([^A-F0-9{2}])", "%25\1", "ALL"));
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson