Skip to content

Update GeoIP2.php to not crash on multiple addresses #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Provider/GeoIP2/GeoIP2.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public function __construct(GeoIP2Adapter $adapter)
public function geocodeQuery(GeocodeQuery $query): Collection
{
$address = $query->getText();
$address = explode(',', $address)[0];
$locale = $query->getLocale() ?: 'en'; // Default to English
if (!filter_var($address, FILTER_VALIDATE_IP)) {
throw new UnsupportedOperation('The GeoIP2 provider does not support street addresses, only IP addresses.');
throw new UnsupportedOperation(sprintf('"%s" must be called with an IP addresses. Got "%s" instead.', __METHOD__, $address));
}

if ('127.0.0.1' === $address) {
Expand Down Expand Up @@ -110,6 +111,7 @@ public function getName(): string
*/
private function executeQuery(string $address): string
{
$address = explode(',', $address)[0];
$uri = sprintf('file://geoip?%s', $address);

try {
Expand Down