diff --git a/src/Countries.php b/src/Countries.php index fa40773..0075051 100644 --- a/src/Countries.php +++ b/src/Countries.php @@ -355,7 +355,11 @@ public function inEurope(string $code) : bool */ public function ip(string $ipAddress) : string { - $url = 'https://ip2c.org/' . $ip; + if (empty($ipAddress)) { + return ''; + } + + $url = sprintf('https://ip2c.org/%s', urlencode($ipAddress)); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); diff --git a/tests/CountriesTest.php b/tests/CountriesTest.php index 2e5d5e1..3e09fdc 100644 --- a/tests/CountriesTest.php +++ b/tests/CountriesTest.php @@ -33,5 +33,13 @@ public function testInEurope() { self::assertTrue( $countries->inEurope( $country ) ); } } + + /** + * @covers Countries::ip + */ + public function testIp() { + $countries = new Countries(); + self::assertEmpty($countries->ip('')); + } }