CFFEED - You have failed me for the last time.

This is your CFML. This is your CFML with cffeed. Ugh. I give up. Today a customer of ours at Broadchoice ran into a bug with an RSS feed. The feed was being generated by cffeed of course. What was interesting is that this was a whole new bug for me. Yes, another one. I swear I love ColdFusion. Really, I do. I just don’t know why this one darn tag seems to trouble me so much. I swear this tag has a personal vendetta against me. So what went wrong this time?
The error was thrown by CFFEED. It wasn’t an error on display, like what I describe here. I carefully read over the content that was being used for the feed data and then I saw it. The mysterious box of doom I like to call it. The character that obviously was pasted from some Word document, or other source, that got fubared when rendered.

It took me a while, but I was able to narrow down the character (19) and expose the error a bit. To see this in action, I modified the code from the blog entry mentioned above.

<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)# #chr(19)#”)> <cfset querySetCell(getEntries,”publisheddate”, now())>

<cfset props = {version=”rss_2.0”,title=”Test Feed”,link=”http://127.0.0.1”,description=”Test”}>

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

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

Note the data in the second query row. I added the chr(19) to the end. Now unlike the problem in the other blog entry (which resulted in Firefox not showing the complete feed), this one threw a real exception:

The input values might be invalid. The reason for exception is :
The data "Test X" is not legal for a JDOM character content: 0x13 is not a legal XML character.

As just an FYI, the “X” above was the literal bad character. I replied it so as to not cause any possible problems in my own RSS feed here.

Great. Not a legal XML character. Hey, I bet xmlFormat() will fix it, right? Of course not. As I said in the beginning. Ugh.

So to fix it, I modified the UDF mentioned in the earlier blog entry to just replace chr(19) with nothing.

You know - I get that different encodings can impact whats valid in XML. But would it be that hard to ask cffeed to sniff the current settings and just remove what isn’t valid? Especially since it will be (most likely) crap characters like funky quotes or the like? Seriously - am I the only one having so much trouble with cffeed?

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.

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

Comments