Merge pull request #14736 from MrPetovan/bug/fatal-errors
Ward against invalid URLs in Model\Post\Media::isFederatedServer
This commit is contained in:
commit
80f5856764
1 changed files with 15 additions and 9 deletions
|
@ -10,6 +10,7 @@ namespace Friendica\Model\Post;
|
|||
use Friendica\Content\PageInfo;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -255,16 +256,21 @@ class Media
|
|||
|
||||
private static function isFederatedServer(string $url): bool
|
||||
{
|
||||
$baseurl = Network::getBaseUrl(new Uri($url));
|
||||
if (empty($baseurl)) {
|
||||
try {
|
||||
$baseurl = Network::getBaseUrl(new Uri($url));
|
||||
if (empty($baseurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Strings::compareLink($baseurl, ATProtocol::WEB)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return DBA::exists('gserver', ['nurl' => Strings::normaliseLink($baseurl), 'network' => Protocol::FEDERATED]);
|
||||
} catch(\Throwable $e) {
|
||||
DI::logger()->notice('Invalid URL provided', ['url' => $url, 'exception' => $e, 'callstack' => System::callstack(10)]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Strings::compareLink($baseurl, ATProtocol::WEB)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return DBA::exists('gserver', ['nurl' => Strings::normaliseLink($baseurl), 'network' => Protocol::FEDERATED]);
|
||||
}
|
||||
|
||||
private static function addPreviewData(array $media): array
|
||||
|
@ -790,7 +796,7 @@ class Media
|
|||
}
|
||||
|
||||
// Search for links with descriptions
|
||||
if (preg_match_all("/\[url\=(https?:.*?)\].*?\[\/url\]/ism", $body, $matches)) {
|
||||
if (preg_match_all("#\[url=(https?://.+?)].+?\[/url]#ism", $body, $matches)) {
|
||||
foreach ($matches[1] as $url) {
|
||||
DI::logger()->info('Got page url (link with description)', ['uri-id' => $uriid, 'url' => $url]);
|
||||
$result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue