Skip to content

Commit

Permalink
Support IP search with port
Browse files Browse the repository at this point in the history
[3ffe:0b00:000:0000:0001:0000:0000:000a]:80 should be valid
  • Loading branch information
gdomingu committed Apr 14, 2020
1 parent cfb14aa commit dac0ae2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/geocoder/ip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def private?
end

def valid?
!!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex))
ip = self[/(?<=\[)(.*?)(?=\])/] || self
!!((ip =~ Resolv::IPv4::Regex) || (ip =~ Resolv::IPv6::Regex))
end
end
end
1 change: 1 addition & 0 deletions test/unit/ip_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_valid
assert !Geocoder::IpAddress.new("232.65.123").valid?
assert !Geocoder::IpAddress.new("::ffff:123.456.789").valid?
assert !Geocoder::IpAddress.new("Test\n232.65.123.94").valid?
assert Geocoder::IpAddress.new("[3ffe:0b00:000:0000:0001:0000:0000:000a]:80").valid?
end

def test_internal
Expand Down

0 comments on commit dac0ae2

Please sign in to comment.