mirror of
https://github.com/friendica/friendica
synced 2025-05-05 17:44:10 +02:00
Sanitize links before storing them
This commit is contained in:
parent
fe00a3893d
commit
061f43788c
4 changed files with 31 additions and 28 deletions
|
@ -659,6 +659,29 @@ class Network
|
|||
return !empty($scheme) && in_array($scheme, ['http', 'https']) && parse_url($url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove invalid parts from an URL
|
||||
*
|
||||
* @param string $url
|
||||
* @return string sanitized URL
|
||||
*/
|
||||
public static function sanitizeUrl(string $url): string
|
||||
{
|
||||
$sanitized = $url = trim($url);
|
||||
|
||||
foreach (['"', ' '] as $character) {
|
||||
$pos = strpos($sanitized, $character);
|
||||
if ($pos !== false) {
|
||||
$sanitized = trim(substr($sanitized, 0, $pos));
|
||||
}
|
||||
}
|
||||
|
||||
if ($sanitized != $url) {
|
||||
Logger::debug('Link got sanitized', ['url' => $url, 'sanitzed' => $sanitized]);
|
||||
}
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Uri object out of a given Uri string
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue