Bug to watch out for with CFFEED

So I've blogged before about how xmlFormat() is a bit buggy. While it will remove most characters, including "high ascii" characters in the range of 128-255, it will gleefully ignore other high ascii characters, for example, character 8220 which is the funky Microsoft Word quote. Unfortunately it looks like the same code used for xmlFormat is used to escape text when you create feeds with CFFEED. Consider the following example:

<cfset getEntries = queryNew("publisheddate,content,title")>

<cfset queryAddRow(getEntries)> <cfset querySetCell(getEntries,"title", "LAST ENTRY")> <cfset querySetCell(getEntries,"content", "<b>Test</b>")> <cfset querySetCell(getEntries,"publisheddate", now())>

<cfset queryAddRow(getEntries)> <cfset querySetCell(getEntries,"title", "LAST ENTRY2")> <cfset querySetCell(getEntries,"content", "#chr(8220)#Test#chr(8220)#")> <cfset querySetCell(getEntries,"publisheddate", now())>

<cfset props = {version="rss_2.0",title="Test Feed",link="",description="Test"}>

<cffeed action="create" properties="#props#" query="#getEntries#" xmlVar="result">

<cfcontent type="text/xml" reset="true"><cfoutput>#result#</cfoutput>

The first entry will correctly show up in Firefox, but the second will not, and if you view source, you see the B tags are properly escaped, but the funky MS Word character is not. Now obviously I can make sure to "clean" my data before it gets used in the feed, but I wasn't aware this was an even an issue until a friend reported that the feed at ColdFusionBloggers suddenly turned up empty. For now I've switched to the solution below - which is not a good solution, but I needed a quick fix.

<!--- clean up bad stuff ---> <cfloop query="items"> <cfset fixedcontent = replaceList(content, "#chr(25)#,#chr(212)#,#chr(248)#,#chr(937)#,#chr(8211)#", "")> <cfset fixedcontent = replaceList(fixedcontent,chr(8216) & "," & chr(8217) & "," & chr(8220) & "," & chr(8221) & "," & chr(8212) & "," & chr(8213) & "," & chr(8230),"',',"","",--,--,...")> <cfset querySetCell(items, "content", fixedcontent, currentRow)> </cfloop>

<cffeed action="create" properties="#props#" columnMap="#cmap#" query="#items#" xmlVar="result">

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com