mirror of
https://github.com/friendica/friendica
synced 2025-05-04 11:04:09 +02:00
Fix exception, when a provided URI is invalid
This commit is contained in:
parent
49819b64db
commit
7b1b3fe8cf
2 changed files with 28 additions and 6 deletions
|
@ -658,4 +658,25 @@ class Network
|
|||
$scheme = parse_url($url, PHP_URL_SCHEME);
|
||||
return !empty($scheme) && in_array($scheme, ['http', 'https']) && parse_url($url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a provided URI is valid
|
||||
*
|
||||
* @param string|null $uri
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidUri(string $uri = null): bool
|
||||
{
|
||||
if (empty($uri)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
new Uri($uri);
|
||||
} catch (\Exception $e) {
|
||||
Logger::debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue