Now that we know how to create our own CFML tag in Railo Server, it won't be very hard to create our own CFML function. And indeed, it isn't!
Let's create the function cleanScope()
, which cleans the contents of a scope like URL or form (or any CFML structure actually). This could save us some lines of code in our next project:
1. Create a file with the following content:
<cffunction name="cleanscope" output="false" access="public" returntype="any" hint="I clean a given struct/array from spaces and script injection"> <cfargument name="scope" type="any" required="true" hint="The scope to clean (e.g. URL of form)" /> <cfset var key = "" /> <cfif not isStruct(arguments.scope) and not isArray(arguments.scope)> <cfthrow message="The argument for function cleanscope must be either a struct or array!" /> </cfif> <cfloop collection="#arguments.scope#" item="key"> <!--- if the value is a simple value (string...