coldfusionhtml-escape-characterscoldfusion-2016xml-encoding

Escaping and unescaping HTML


In a function I do not control, data is being returned via

return xmlFormat(rc.content)

I later want to do a

<cfoutput>#resultsofreturn#</cfoutput>

The problem is all the HTML tags are escaped.

I have considered

<cfoutput>#DecodeForHTML(resultsofreturn)#</cfoutput>

But I am not sure these are inverses of each other


Solution

  • Like Adrian concluded, the best option is to implement a system to get to the pre-encoded value.

    In the current state, the string your working with is encoded for an xml document. One option is to create an xml document with the text and parse the text back out of the xml document. I'm not sure how efficient this method is, but it will return the text back to it's pre-encoded value.

    function xmlDecode(text){
        return xmlParse("<t>#text#</t>").t.xmlText;
    }
    

    TryCF.com example