]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rss: watch handle case during rename
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 25 Nov 2010 16:53:57 +0000 (17:53 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 25 Nov 2010 16:53:57 +0000 (17:53 +0100)
We allow rss handles to be of any case on creation, even though matching
is case-insentivie. However, when renaming an rss using 'rss change
handle' and only changing the case, two things prevented this from
working correctly:
* since the new downcased handle was equal to the old downcased handle,
  the bot would prevent the renaming due to the existence of the new
  handle
* the new handle was forcefully downcased, preventing the user
  from renaming handle 'case' to 'CaSe'.

Fix by checking for this case explicitly, and handling it separately.

data/rbot/plugins/rss.rb

index 3b09930ab723539cf05197c51612268ea5759149..eb3fa5f86b1bcb60be626006f323b91ac1341a14 100644 (file)
@@ -781,15 +781,28 @@ class RSSFeedsPlugin < Plugin
     end
     case params[:what].intern
     when :handle
-      new = params[:new].downcase
-      if @feeds.key?(new) and @feeds[new]
+      # preserve rename case, but beware of key
+      realnew = params[:new]
+      new = realnew.downcase
+      if feed.handle.downcase == new
+        if feed.handle == realnew
+          m.reply _("You want me to rename %{handle} to itself?") % {
+            :handle => feed.handle
+          }
+          return false
+        else
+          feed.mutex.synchronize do
+            feed.handle = realnew
+          end
+        end
+      elsif @feeds.key?(new) and @feeds[new]
         m.reply "There already is a feed with handle #{new}"
         return
       else
         feed.mutex.synchronize do
           @feeds[new] = feed
           @feeds.delete(handle)
-          feed.handle = new
+          feed.handle = realnew
         end
         handle = new
       end