Filtering the_title_rss: show me the whitespace!

Before I decided that the only workable solution to my silent data loss problem was that we would all make the switch to Atom, now, I was trying to find a middle ground that would please the contradictory desires of both the feedvalidator and every RSS consuming application on earth by writing a WordPress plugin that would do some escaping by adding a filter for the_title_rss. Yeah. Me? Plugin? You know that’ll descend quickly into tears and broken household objects.

WordPress filter plugins are simple enough: a hot comment with some metadata for the plugin manager, a function that does what you want, and a call to add_filter(). But when I enabled it and refreshed my feed in Firefox, there was a small explosion and fire, followed by an error message claiming it wasn’t properly gzipped. Once I disabled compression, the explosion was due to a well-formedness error resulting from a blank line before the <?xml...> declaration. The bug database tells me that it’s my fault, for having some extraneous whitespace, so could someone help me out and show me the whitespace in that? I did actually try collapsing the comment as well, so it’s all a single line, but although that breaks the hot comment parser, it still outputs the stray newline, almost like it’s not really my fault.

I will not leave trailing newlines after PHP end delimiters. × 1000.

7 Comments

Comment by skippy #
2005-11-08 09:04:00

Looks to me like there’s an extra space at the end of the file, not the beginning. This too makes PHP angry.

 
Comment by skippy #
2005-11-08 09:05:37

Addendum: I’ve removed the trailing whitespace, and activated the plugin on my blog. Nothing seems to have broken.

 
Comment by Phil Ringnalda #
2005-11-08 09:27:33

Arrrgh!

Thanks. I know better, really I do. At least, at reasonable hours of the day, I do, sometimes.

Comment by Matt #
2005-11-08 10:53:18

Yep, you can add the whitespace back inside the PHP tags, it’s only outside that it causes trouble.

 
 
Comment by Frenzie #
2005-11-08 10:14:41

Looks to me like there’s a whole blank line on the bottom rather than a whitespace? Either way, you should remove that.

@skippy: PHP doesn’t get angry, it simply does what you tell it to do. Put a blank line there. Firefox’ XML parser can’t digest it which is a whole different topic.

Comment by Frenzie #
2005-11-08 10:15:51

Please exuse this comment and feel free to delete it. I didn’t realise I had already opened this page before dinner.

Comment by Phil Ringnalda #
2005-11-08 13:35:49

No problem: I’m always happier to get the same answer twice than to get no answer at all.

 
 
 

Sorry, the comment form is closed at this time.