diff --git a/ChangeLog b/ChangeLog index ca81ef8447..d83374efd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 22 14:37:43 2005 Kouhei Sutou + + * 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. + Fri Jul 22 07:01:42 2005 Hidetoshi NAGAI * ext/tk/tkutil/tkutil.c (tk_conv_args): forget to revert diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 7e93c62f61..df268da1e7 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 /