X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Futils%2Fwordlist.rb;h=4e624f9b4e80b9d0aa64a00855ee4c72c5913894;hb=be5d914984e767ce1a718b84d0bad1c88d9f8ea3;hp=63cc99a7c8808e04200f3b0b863e3ee8950d5f8f;hpb=102fab9a892f39bc77a92db37f6f77f77a7f0f2f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/utils/wordlist.rb b/lib/rbot/core/utils/wordlist.rb index 63cc99a7..4e624f9b 100755 --- a/lib/rbot/core/utils/wordlist.rb +++ b/lib/rbot/core/utils/wordlist.rb @@ -11,7 +11,7 @@ module ::Irc class Bot class Wordlist def self.wordlist_base - @@wordlist_base ||= File.join(Utils.bot.botclass, 'wordlists') + @@wordlist_base ||= Utils.bot.path 'wordlists' end def self.get(path, options={}) @@ -33,7 +33,8 @@ class Wordlist File.readlines(wordlist_path) end - wordlist.map! { |l| l.strip } + # wordlists are assumed to be UTF-8, but we need to strip the BOM, if present + wordlist.map! { |l| l.sub("\xef\xbb\xbf",'').strip } wordlist.reject do |word| word =~ /\s/ && !opts[:spaces] || word.empty? @@ -52,6 +53,14 @@ class Wordlist name[striplen..-1] } end + + def self.exist?(path) + fn = path.to_s + # refuse to check outside of the wordlist base directory + return false if fn =~ /\.\.\// + File.exist?(File.join(self.wordlist_base, fn)) + end + end end end