From 4f7c77e93e62fb16f04c51587ac91aef82d122a4 Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Sat, 4 Jan 2020 21:46:03 -0500 Subject: [PATCH] Sanity check to MaxMind records --- Changes | 3 +++ lib/Geo/Coder/Free/MaxMind.pm | 4 ++++ t/admin1.t | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 7531595..f5d7275 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Geo-Coder-Free +0.24 + Sanity check to MaxMind records + 0.23 Save database in Redis server as well if REDIS_SERVER is set Fixed reverse_geocode in Local.pm for UK addresses diff --git a/lib/Geo/Coder/Free/MaxMind.pm b/lib/Geo/Coder/Free/MaxMind.pm index fddd060..1043f8f 100644 --- a/lib/Geo/Coder/Free/MaxMind.pm +++ b/lib/Geo/Coder/Free/MaxMind.pm @@ -439,6 +439,10 @@ sub geocode { my @locations; foreach my $l(@rc) { + if(!exists($l->{'latitude'})) { + Carp::carp(__PACKAGE__, ": $location has latitude of 0"); + return; + } push @locations, Geo::Location::Point->new({ 'lat' => $l->{'latitude'}, 'long' => $l->{'longitude'}, diff --git a/t/admin1.t b/t/admin1.t index 3a7ddab..ae94790 100644 --- a/t/admin1.t +++ b/t/admin1.t @@ -17,8 +17,8 @@ CITIES: { my $admin1 = new_ok('Geo::Coder::Free::DB::MaxMind::admin1' => [logger => new_ok('MyLogger'), no_entry => 1]); my $england = $admin1->fetchrow_hashref({ concatenated_codes => 'GB.ENG' }); - ok($england->{asciiname} eq 'England'); + is($england->{asciiname}, 'England'); $england = $admin1->fetchrow_hashref({ asciiname => 'England' }); - ok($england->{concatenated_codes} eq 'GB.ENG'); + is($england->{concatenated_codes}, 'GB.ENG'); }