summaryrefslogtreecommitdiffstats
path: root/lib/rss
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-22 05:41:33 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-22 05:41:33 +0000
commitd5c9cfd09d5ceff8b490597f5f8ebf219479fbc1 (patch)
tree974b3a7063a8e72db327eaad3d2c67ac53d6efb4 /lib/rss
parenta428c6e7cf97db93d09b374adf17783c03546f5a (diff)
downloadruby-d5c9cfd09d5ceff8b490597f5f8ebf219479fbc1.tar.gz
ruby-d5c9cfd09d5ceff8b490597f5f8ebf219479fbc1.tar.xz
ruby-d5c9cfd09d5ceff8b490597f5f8ebf219479fbc1.zip
* lib/rss/parser.rb (RSS::Parser#initialize): accept HTTP/FTP
URI and local file path too. * test/rss/test_parser.rb (RSS::TestParser#test_parse): test for the above. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss')
-rw-r--r--lib/rss/parser.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
index 7e93c62f6..df268da1e 100644
--- a/lib/rss/parser.rb
+++ b/lib/rss/parser.rb
@@ -1,4 +1,5 @@
require "forwardable"
+require "open-uri"
require "rss/rss"
@@ -77,7 +78,36 @@ module RSS
:do_validate=)
def initialize(rss, parser_class=self.class.default_parser)
- @parser = parser_class.new(rss)
+ @parser = parser_class.new(normalize_rss(rss))
+ end
+
+ private
+ def normalize_rss(rss)
+ return rss if maybe_xml?(rss)
+
+ uri = to_uri(rss)
+
+ if uri.respond_to?(:read)
+ uri.read
+ elsif !rss.tainted? and File.readable?(rss)
+ File.open(rss) {|f| f.read}
+ else
+ rss
+ end
+ end
+
+ def maybe_xml?(source)
+ source.is_a?(String) and /</ =~ source
+ end
+
+ def to_uri(rss)
+ return rss if rss.is_a?(::URI::Generic)
+
+ begin
+ URI(rss)
+ rescue ::URI::Error
+ rss
+ end
end
end