pauldix/feedzirra — pull request #166 by pgib (2013-07-21 20:42:40+00:00)
Title: Support xml:base for Atom feed and feed entries

The Atom standard support an xml:base= attribute in the and

nodes which is supposed to be used as a base when defined for any s that are used. [Tim Bray](http://en.wikipedia.org/wiki/Tim_Bray)'s [blog](https://www.tbray.org/ongoing/ongoing.atom) famously (infamously?) uses this Atom capability which causes problems for any Atom parser that doesn't fully implement the spec.

Prior to this PR, this is what we'd have:

feed = Feedzirra::Feed.fetch_and_parse("https://www.tbray.org/ongoing/ongoing.atom")

feed.url
# => "/home/tbray.org/www/html/ongoing/comments.atom"

feed.feed_url
# => "https://www.tbray.org/ongoing/ongoing.atom"

feed.entries.first.url
# => "Luma-Cinch-and-Helios-M44m-58m"

The call to `feed.feed_url` only actually works because https://github.com/pauldix/feedzirra/blob/master/lib/feedzirra/feed.rb#L281 explicitly sets it after a remote fetch. But if you load the same feed from a cached file, you get:

feed = Feedzirra::Parser::Atom.parse(File.read('ongoing.atom'))
feed.feed_url
# => "http://pubsubhubbub.appspot.com/"

The #url on any entry disregards the `xml:base=` attribute, and then services like [Feedbin](http://feedbin.me) which use this library try to take the user to a broken URL (on any Atom feed that uses and relies on xml:base).

With this PR, we now get:

feed = Feedzirra::Feed.fetch_and_parse("https://www.tbray.org/ongoing/ongoing.atom")

feed.url
# => "https://www.tbray.org/ongoing/"

feed.feed_url
# => "https://www.tbray.org/ongoing/ongoing.atom"

feed.entries.first.url
# => "When/201x/2013/07/20/Luma-Cinch-and-Helios-M44m-58m"

The results are the same if fetching remotely or using a cached feed file.

Related: https://github.com/feedbin/support/issues/110