Merge pull request #12440 from MrPetovan/bug/fatal-errors
Catch exceptions in Model\Gserver::cleanURL
This commit is contained in:
commit
22c1cd3cd1
1 changed files with 8 additions and 13 deletions
|
@ -314,25 +314,20 @@ class GServer
|
||||||
/**
|
/**
|
||||||
* Remove unwanted content from the given URL
|
* Remove unwanted content from the given URL
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $dirtyUrl
|
||||||
*
|
*
|
||||||
* @return string cleaned URL
|
* @return string cleaned URL
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function cleanURL(string $url): string
|
public static function cleanURL(string $dirtyUrl): string
|
||||||
{
|
{
|
||||||
$url = trim($url, '/');
|
try {
|
||||||
$url = str_replace('/index.php', '', $url);
|
$url = str_replace('/index.php', '', trim($dirtyUrl, '/'));
|
||||||
|
return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment('');
|
||||||
$urlparts = parse_url($url);
|
} catch (\Throwable $e) {
|
||||||
if (empty($urlparts)) {
|
Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($urlparts['user']);
|
|
||||||
unset($urlparts['pass']);
|
|
||||||
unset($urlparts['query']);
|
|
||||||
unset($urlparts['fragment']);
|
|
||||||
return (string)Uri::fromParts($urlparts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue