]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugin(oxford): fix empty service result see #37
authorMatthias Hecker <mail@apoc.cc>
Mon, 13 Apr 2020 18:55:55 +0000 (20:55 +0200)
committerMatthias Hecker <mail@apoc.cc>
Mon, 13 Apr 2020 18:55:55 +0000 (20:55 +0200)
data/rbot/plugins/oxford.rb

index 5c9b0e4eb4f481f0f0b6411fcac11acf1284430e..eba1b938b54667f8b582e6e9afea7b1a1e26e61e 100644 (file)
@@ -51,8 +51,10 @@ class OxfordPlugin < Plugin
           url = "#{@base_url}/search/dataset.js?dataset=noad&dictionary=en&query=#{CGI.escape word}"
           response = @bot.httputil.get(url, headers: {'X-Requested-With': 'XMLHttpRequest'})
           alternative = response.gsub(/\\/, '').scan(/href="([^"]+)">([^<]+)</)
-          url = @base_url + alternative.first[0]
-          title = alternative.first[1]
+          unless alternative.empty?
+            url = @base_url + alternative.first[0]
+            title = alternative.first[1]
+          end
         end
 
         debug "search for alternative spelling result, returned title=#{title.inspect} url=#{url.inspect}"