Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to escape pound character (#) in ColdFusion?

I have a function in a CFC file that takes a JSON string as an argument. The function then uses the deserialized data to execute an UPDATE query. In the the JSON string, one of the properties has the character # as part of the name. This character makes the code to break in ColdFusion because it is interpreted as a variable. Is there any way to make ColdFusion "escape" that character and consider it just a string? Remember that is part of JSON string.

Below is my function. It doesn't allow me to access dnisObject because of the # characters within the JSON string. If I delete those # from the JSON string it works fine. Those values have to be stored in a database with the #, so I can not just delete them completely.

<cffunction name="updateDnisHproduct" access="remote">
    <cfargument name = "lid" type = "numeric" required = "yes">
    <cfargument name = "updatedObj" type = "string" required="yes">


    <cfset dnisObject = DESERIALIZEJSON(arguments.updatedObj)/>

    <cfset test =[{"phone":"1001106672","lineType":"Outbound","label1":"Voicemail for line #54940","label4":"test","hcat":"18","freshStart":"0","phoneCode":"","hproduct":"3","checked":false},{"phone":"1001106672","lineType":"Outbound","label1":"Voicemail Line Box #58940","label4":"12","hcat":"54","freshStart":"0","phoneCode":"","hproduct":"12","checked":false}'>

    <cfset dnisObject = DESERIALIZEJSON(test)/>
</cffunction>
like image 666
DoArNa Avatar asked Dec 13 '22 23:12

DoArNa


1 Answers

Same way you normally escape pound signs: double them. From the documentation:

...To include [pound signs] in a string, double the character; for example, use ## to represent a single # character.

Since the input is a string, just do a Replace() to substitute a single pound sign with two pound signs.

like image 154
Leigh Avatar answered Dec 17 '22 02:12

Leigh