From dac0ae2a5cc13c80e7c5e23f9fa60015523d67df Mon Sep 17 00:00:00 2001 From: Gabe D Date: Mon, 13 Apr 2020 17:08:24 -0700 Subject: [PATCH] Support IP search with port [3ffe:0b00:000:0000:0001:0000:0000:000a]:80 should be valid --- lib/geocoder/ip_address.rb | 3 ++- test/unit/ip_address_test.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/ip_address.rb b/lib/geocoder/ip_address.rb index c6858cc74..466636a3b 100644 --- a/lib/geocoder/ip_address.rb +++ b/lib/geocoder/ip_address.rb @@ -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 diff --git a/test/unit/ip_address_test.rb b/test/unit/ip_address_test.rb index e2dedf79e..1be4c8d16 100644 --- a/test/unit/ip_address_test.rb +++ b/test/unit/ip_address_test.rb @@ -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