Interesting CFFEED Issue with Spaces

This post is more than 2 years old.

Heh, yes, I'm back to my favorite tag to pick on. A user sent in an interesting problem he was having with cffeed. When he used a value for the source that came from a query, he got an error. When he hard coded a URL in, it worked just fine. I looked over his code and as far as I could see, everything seemed fine. The error itself was pretty weird as well:

Unable to read the feed source file /Users/ray/Documents/Web Sites/webroot/http:/

As you can see, the feed url ( was somehow being munged into a local path. I added a debug statement to the output and then I noticed it. A slight space between my debug line and the actual value. Turned out the data from the query had an extra white space in front of the URL. You can reproduce this problem yourself with the following code:

<cfset theURL = "">

<cffeed action="read" source="#theURL#" properties="meta" query="items"> <cfdump var="#items#">

Most likely the data was based on user input and he forgot to trim before entering the data into the database. It was easy enough to fix of course:

<cfset theURL = "">

<cffeed action="read" source="#trim(theURL)#" properties="meta" query="items"> <cfdump var="#items#">

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, 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

Archived Comments

Comment 1 by dfguy posted on 10/8/2008 at 10:16 PM

and exactly how is this CFEED's problem? seems to me that if he forgets to sanitize his input, it's his fault.

Comment 2 by Raymond Camden posted on 10/8/2008 at 10:27 PM

True - but one could argue that CFFEED makes an odd decision on switching to file based lookups because of the space.

Comment 3 by dfguy posted on 10/8/2008 at 10:38 PM

why is it strange? filenames can have spaces in them, urls cannot per rfc 1738.

Comment 4 by Raymond Camden posted on 10/8/2008 at 10:39 PM

True. I'm guessing their back end code does: if url, fetch, else load from file system, and the if url fails on the space. Of course, it works just fine if you add a space at the end. That's what threw me at first.

Either way - this post really wasn't meant to assign blame per se, but to serve as a warning, as it certainly wasn't obvious what was going on.