diff --git a/lib/geocoder.rb b/lib/geocoder.rb index 4e48a312012e4388f865a624df708d21641bbb13..692551e8998938ad58aaa4adf3583664c99ccb39 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -115,7 +115,7 @@ module Geocoder # dot-delimited numbers. # def ip_address?(value) - !!value.to_s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) + !!value.to_s.match(/^(::ffff:)?(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) end ## diff --git a/test/input_handling_test.rb b/test/input_handling_test.rb index 9d453b97b562c615bc82178495dba36c05e9d9a7..f5da1f13c9df941fdbf08a157464a0dbb0738d7c 100644 --- a/test/input_handling_test.rb +++ b/test/input_handling_test.rb @@ -6,8 +6,10 @@ class InputHandlingTest < Test::Unit::TestCase def test_ip_address_detection assert Geocoder.send(:ip_address?, "232.65.123.94") assert Geocoder.send(:ip_address?, "666.65.123.94") # technically invalid + assert Geocoder.send(:ip_address?, "::ffff:12.34.56.78") assert !Geocoder.send(:ip_address?, "232.65.123.94.43") assert !Geocoder.send(:ip_address?, "232.65.123") + assert !Geocoder.send(:ip_address?, "::ffff:123.456.789") end def test_blank_query_detection