Not So SimplePie
Next to RSS and Atom (and JSON Feed), my feed reader also supports h-feed. To parse h-feeds (or microformats feeds, of mf2 feeds), it (indirectly) relies on the php-mf2 library.
All things RSS and Atom, on the other hand, are handled by SimplePie (a very popular feed parsing library that ships with, e.g., WordPress).
One of the feeds I’m subscribed to is This Week in the IndieWeb. Like most feeds, it contains entries, and those entries often contain HTML. Which is good!
Unlike most (RSS or Atom) feeds, some of that HTML includes things like class="h-entry"
. (Also good, but wait.)
Turns out SimplePie itself comes with (very basic) h-feed support. (Good, too, but wait.)
SimplePie’s microformats functions will kick in only if both the php-mf2 library is detected and a “feed” (which, like h-feed, can be an HTML document, too) contains something that looks like … an h-entry
class.
Now, whenever you—and only when those exact conditions are met—feed (no pun intended) SimplePie an otherwise perfectly valid RSS document, it will return … nothing. No entries found.
Which is to be expected; php-mf2 expects HTML, not RSS (or Atom). Still, not so good. (Thing is, SimplePie’s microformats functions, as long as these conditions are met, will kick in also if said feed is an XML feed.)
One easy solution is to comment out the few lines of code, in SimplePie, that call its microformats parser. My feed reader has its own way of detecting microformats feeds anyway. But that means “actively” maintaining a fork, syncing future changes, and so on.
Another is to simply remove these classes (i.e., h-feed
and h-entry
) from XML feeds before they’re fed to SimplePie. (There isn’t a problem with other microformats classes, like u-*
and p-*
.)
The ultimate solution would be for SimplePie to first verify that a feed really isn’t an XML feed and only then try to look for microformats. The way X-Ray does it, too. Haven’t done a pull request in ages—repo owners tend to, uh, ignore them—but I might eventually give this one a try.