mirror of
https://github.com/funamitech/mastodon
synced 2024-11-28 06:48:45 +09:00
Fix uncaught ActiveRecord::StatementInvalid
in Mastodon::IpBlocksCLI (#24861)
This commit is contained in:
parent
aec486b4ec
commit
ffb3fef7db
@ -36,6 +36,12 @@ module Mastodon
|
|||||||
failed = 0
|
failed = 0
|
||||||
|
|
||||||
addresses.each do |address|
|
addresses.each do |address|
|
||||||
|
unless valid_ip_address?(address)
|
||||||
|
say("#{address} is invalid", :red)
|
||||||
|
failed += 1
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
ip_block = IpBlock.find_by(ip: address)
|
ip_block = IpBlock.find_by(ip: address)
|
||||||
|
|
||||||
if ip_block.present? && !options[:force]
|
if ip_block.present? && !options[:force]
|
||||||
@ -79,6 +85,12 @@ module Mastodon
|
|||||||
skipped = 0
|
skipped = 0
|
||||||
|
|
||||||
addresses.each do |address|
|
addresses.each do |address|
|
||||||
|
unless valid_ip_address?(address)
|
||||||
|
say("#{address} is invalid", :yellow)
|
||||||
|
skipped += 1
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
ip_blocks = if options[:force]
|
ip_blocks = if options[:force]
|
||||||
IpBlock.where('ip >>= ?', address)
|
IpBlock.where('ip >>= ?', address)
|
||||||
else
|
else
|
||||||
@ -126,5 +138,12 @@ module Mastodon
|
|||||||
:red
|
:red
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_ip_address?(ip_address)
|
||||||
|
IPAddr.new(ip_address)
|
||||||
|
true
|
||||||
|
rescue IPAddr::InvalidAddressError
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user