From 1e7bea5fae49e6d73d2542d773747d8101a10f48 Mon Sep 17 00:00:00 2001 From: "Rudy X. Desjardins" Date: Fri, 18 Feb 2011 16:14:51 -0500 Subject: [PATCH] Some small changes to allow (explicit) loading of feeds using a bad content type, and a fix for feeds containing non-escaped uris... and a couple other tiny changes to require lines (ie: digest/md5 instead of md5) --- lib/atom/cache.rb | 2 +- lib/atom/element.rb | 5 +++++ lib/atom/feed.rb | 10 ++++++---- lib/atom/http.rb | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/atom/cache.rb b/lib/atom/cache.rb index 3234f95..06a6901 100644 --- a/lib/atom/cache.rb +++ b/lib/atom/cache.rb @@ -3,7 +3,7 @@ # # used under the terms of the MIT license -require "md5" +require "digest/md5" def normalize_header_names _headers headers = {} diff --git a/lib/atom/element.rb b/lib/atom/element.rb index e00ef1b..c34fea0 100644 --- a/lib/atom/element.rb +++ b/lib/atom/element.rb @@ -1,5 +1,6 @@ require "time" require "rexml/element" +require "uri" require 'uri' @@ -597,6 +598,10 @@ def self.parse xml, base = '' # URL absolutization if !e.base.empty? and e.href + # url-encode necessary chars + e.base = URI.escape e.base + e.href = URI.escape e.href + e.href = (e.base.to_uri + e.href).to_s end diff --git a/lib/atom/feed.rb b/lib/atom/feed.rb index 6091bfa..125e824 100644 --- a/lib/atom/feed.rb +++ b/lib/atom/feed.rb @@ -157,7 +157,7 @@ def merge other_feed # changes, new entries, &c. # # (note that this is different from Atom::Entry#updated! - def update! + def update!(check_content_type = true) raise(RuntimeError, "can't fetch without a uri.") unless @uri res = @http.get(@uri, "Accept" => "application/atom+xml") @@ -172,9 +172,11 @@ def update! end # we'll be forgiving about feed content types. - res.validate_content_type(["application/atom+xml", - "application/xml", - "text/xml"]) + if check_content_type + res.validate_content_type(["application/atom+xml", + "application/xml", + "text/xml"]) + end @etag = res["ETag"] if res["ETag"] diff --git a/lib/atom/http.rb b/lib/atom/http.rb index fd84c6b..6dbfe38 100644 --- a/lib/atom/http.rb +++ b/lib/atom/http.rb @@ -4,7 +4,7 @@ require "atom/cache" -require "sha1" +require "digest/sha1" require "digest/md5" module URI # :nodoc: all