Skip to content

Commit dac0ae2

Browse files
committed
Support IP search with port
[3ffe:0b00:000:0000:0001:0000:0000:000a]:80 should be valid
1 parent cfb14aa commit dac0ae2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/geocoder/ip_address.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def private?
2020
end
2121

2222
def valid?
23-
!!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex))
23+
ip = self[/(?<=\[)(.*?)(?=\])/] || self
24+
!!((ip =~ Resolv::IPv4::Regex) || (ip =~ Resolv::IPv6::Regex))
2425
end
2526
end
2627
end

test/unit/ip_address_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_valid
1313
assert !Geocoder::IpAddress.new("232.65.123").valid?
1414
assert !Geocoder::IpAddress.new("::ffff:123.456.789").valid?
1515
assert !Geocoder::IpAddress.new("Test\n232.65.123.94").valid?
16+
assert Geocoder::IpAddress.new("[3ffe:0b00:000:0000:0001:0000:0000:000a]:80").valid?
1617
end
1718

1819
def test_internal

0 commit comments

Comments
 (0)