diff --git a/config/initializers/user_spam_scorer.rb b/config/initializers/user_spam_scorer.rb index 0c68a613558..95b8ac9ea30 100644 --- a/config/initializers/user_spam_scorer.rb +++ b/config/initializers/user_spam_scorer.rb @@ -6,13 +6,6 @@ if File.exist?(path) settings = YAML.load(File.read(path))['user_spam_scorer'] settings.each do |key, value| - case key - when 'ip_ranges' - value = value.map { |v| IPAddr.new(v) } - when /_format/ - raise "UserSpamScorer: Can't load Regexp from YAML file" - end - UserSpamScorer.public_send("#{key}=", value) end end diff --git a/lib/user_spam_scorer.rb b/lib/user_spam_scorer.rb index d61501609ab..2976af068e2 100644 --- a/lib/user_spam_scorer.rb +++ b/lib/user_spam_scorer.rb @@ -211,7 +211,7 @@ def user_agent_is_suspicious?(user) def ip_range_is_suspicious?(user) return false unless user.respond_to?(:ip) - suspicious_ip_ranges.any? { |range| range.include?(user.ip) } + suspicious_ip_ranges.any? { |range| IPAddr.new(range).include?(user.ip) } end # TODO: Akismet thinks user is spam diff --git a/spec/lib/user_spam_scorer_spec.rb b/spec/lib/user_spam_scorer_spec.rb index d747d1d5ade..353db2b64b6 100644 --- a/spec/lib/user_spam_scorer_spec.rb +++ b/spec/lib/user_spam_scorer_spec.rb @@ -677,7 +677,7 @@ describe '#ip_range_is_suspicious?' do - before { UserSpamScorer.suspicious_ip_ranges = [IPAddr.new('127.0.0.0/8')] } + before { UserSpamScorer.suspicious_ip_ranges = ['127.0.0.0/8'] } after { UserSpamScorer.reset } it 'is true if the IP address is within a suspicious range' do