Search code examples
javacoldfusioncfmlluceecanonicalization

replacing the special character which is showing as encoded


using canonicalize function to convert a value into a actual single quote:

&#39 

but when I dump the code, it seems good, in db, it is stored as single quote, when loaded in text box, it becomes that character

problem seems to the hash which is popping up and unable to do to decode, is there any other way i can do. this is really messing up


Solution

  • This is a job for EncodeForHTML()

    <cfsavecontent variable="data">&#39</cfsavecontent>
    
    <cfset data = canonicalize(data, true, true)>
    
    <cfoutput>
    <textarea>#EncodeForHTML(data)#</textarea>
    </cfoutput>
    

    It is likely that your entity was not quite correct. Here it is with a ;

    <cfsavecontent variable="data">&#39;</cfsavecontent>
    
    <cfset data = canonicalize(data, true, true)>
    
    <cfoutput>
    <textarea>#EncodeForHTML(data)#</textarea>
    </cfoutput>
    

    See ColdFusion Fiddle: https://cffiddle.org/app/file?filepath=36318397-176d-4b4e-b741-b9f1d2ebc290/1883347c-5e31-4d9c-a759-68938935d066/360cdb86-71f4-47b4-ad90-c19f40b444b6.cfm