]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rss.rb
plugins: raise a descriptive LoadError when the db is corrupt on load
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rss.rb
index f0224a9467727ba9b54c3d7f6ed62bce2e0fe104..7dcfdf6649977a2eccac37961163cae7964848e6 100644 (file)
@@ -315,7 +315,7 @@ class RSSFeedsPlugin < Plugin
   def define_filters
     @outkey = :"rss.out"
     @bot.register_filter(:headlines, @outkey) { |s|
-      line1 = "%{handle}%{title}"
+      line1 = (s[:handle].empty? ? "%{date}" : "%{handle}") << "%{title}"
       make_stream(line1, nil, s)
     }
     @bot.register_filter(:blog, @outkey) { |s|
@@ -445,7 +445,7 @@ class RSSFeedsPlugin < Plugin
       }
 
       @feeds = @registry[:feeds]
-      raise unless @feeds
+      raise LoadError, "corrupted feed database" unless @feeds
 
       @registry.recovery = nil
 
@@ -1092,6 +1092,13 @@ class RSSFeedsPlugin < Plugin
     # reassign the 0.9 RDFs to 1.0, and hope it goes right.
     xml.gsub!("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\"",
               "xmlns=\"http://purl.org/rss/1.0/\"")
+    # make sure the parser doesn't double-convert in case the feed is not UTF-8
+    xml.sub!(/<\?xml (.*?)\?>/) do |match|
+      if /\bencoding=(['"])(.*?)\1/.match(match)
+        match.sub!(/\bencoding=(['"])(?:.*?)\1/,'encoding="UTF-8"')
+      end
+      match
+    end
     feed.mutex.synchronize do
       feed.xml = xml
     end