Skip to content

Commit 71077f8

Browse files
committed
fix maxmind binary provider encondig. Force utf8
1 parent 9b9bbc3 commit 71077f8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Geocoder/Provider/MaxMindBinaryProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,20 @@ public function getGeocodedData($address)
7575
throw new NoResultException(sprintf('No results found for IP address %s', $address));
7676
}
7777

78-
return array_merge($this->getDefaults(), array(
78+
$results = array_merge($this->getDefaults(), array(
7979
'countryCode' => $geoIpRecord->country_code,
8080
'country' => $geoIpRecord->country_name,
8181
'region' => $geoIpRecord->region,
8282
'city' => $geoIpRecord->city,
8383
'latitude' => $geoIpRecord->latitude,
8484
'longitude' => $geoIpRecord->longitude,
8585
));
86+
87+
$results = array_map(function($value) {
88+
return is_string($value) ? utf8_encode($value) : $value;
89+
}, $results);
90+
91+
return $results;
8692
}
8793

8894
/**

tests/Geocoder/Tests/Provider/MaxMindBinaryProviderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
8585
$this->assertEquals($expectedCountry, $result['country']);
8686
}
8787

88+
public function testShouldReturnResultsAsUtf8Encoded()
89+
{
90+
$provider = new MaxMindBinaryProvider($this->binaryFile);
91+
$result = $provider->getGeocodedData('212.51.181.237');
92+
93+
$this->assertSame('Châlette-sur-loing', $result['city']);
94+
}
95+
8896
public function testGetName()
8997
{
9098
$provider = new MaxMindBinaryProvider($this->binaryFile);

0 commit comments

Comments
 (0)