Skip to content

Commit 16b3487

Browse files
committed
Fix encoding for geoip provider
Geoip module return ISO-8859-1 encoded strings. Special characters are broken if not converted to utf8 before applying any transformation (like https://github.com/willdurand/Geocoder/blob/master/src/Geocoder/Result/AbstractResult.php#L64)
1 parent 399681b commit 16b3487

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Geocoder/Provider/GeoipProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getGeocodedData($address)
5858
$timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null;
5959
$region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region'];
6060

61-
return array_merge($this->getDefaults(), array(
61+
$results = array_merge($this->getDefaults(), array(
6262
'latitude' => $results['latitude'],
6363
'longitude' => $results['longitude'],
6464
'city' => $results['city'],
@@ -69,6 +69,12 @@ public function getGeocodedData($address)
6969
'countryCode' => $results['country_code'],
7070
'timezone' => $timezone,
7171
));
72+
73+
$results = array_map(function($value) {
74+
return is_string($value) ? utf8_encode($value) : $value;
75+
}, $results);
76+
77+
return $results;
7278
}
7379

7480
/**

0 commit comments

Comments
 (0)