Merge pull request #12770 from annando/warning

Fixes "Invalid URL for photo" for photos without host
This commit is contained in:
Hypolite Petovan 2023-02-04 07:29:16 -05:00 committed by GitHub
commit 544348c25a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View file

@ -29,6 +29,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityNamespace;
@ -358,13 +359,13 @@ class APContact
$apcontact['discoverable'] = JsonLD::fetchElement($compacted, 'toot:discoverable', '@value'); $apcontact['discoverable'] = JsonLD::fetchElement($compacted, 'toot:discoverable', '@value');
if (!empty($apcontact['photo'])) { if (!empty($apcontact['photo'])) {
$apcontact['photo'] = trim($apcontact['photo']); $apcontact['photo'] = Network::addBasePath($apcontact['photo'], $apcontact['url']);
}
if (!empty($apcontact['photo']) && !Network::isValidHttpUrl($apcontact['photo'])) { if (!Network::isValidHttpUrl($apcontact['photo'])) {
Logger::warning('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]); Logger::warning('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]);
$apcontact['photo'] = ''; $apcontact['photo'] = '';
} }
}
// When the photo is too large, try to shorten it by removing parts // When the photo is too large, try to shorten it by removing parts
if (strlen($apcontact['photo'] ?? '') > 255) { if (strlen($apcontact['photo'] ?? '') > 255) {

View file

@ -120,10 +120,14 @@ class Probe
$numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve']; $numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve'];
if (!empty($data['photo']) && !Network::isValidHttpUrl($data['photo'])) { if (!empty($data['photo'])) {
$data['photo'] = Network::addBasePath($data['photo'], $data['url']);
if (!Network::isValidHttpUrl($data['photo'])) {
Logger::warning('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]); Logger::warning('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]);
unset($data['photo']); unset($data['photo']);
} }
}
$newdata = []; $newdata = [];
foreach ($fields as $field) { foreach ($fields as $field) {
@ -1684,11 +1688,8 @@ class Probe
} }
if ($avatar) { if ($avatar) {
foreach ($avatar->attributes as $attribute) { foreach ($avatar->attributes as $attribute) {
if ($attribute->name == 'src') { if (($attribute->name == 'src') && !empty($attribute->value)) {
$data['photo'] = trim($attribute->value); $data['photo'] = Network::addBasePath($attribute->value, $baseurl);
if (!empty($data['photo']) && !parse_url($data['photo'], PHP_URL_SCHEME) && !parse_url($data['photo'], PHP_URL_HOST)) {
$data['photo'] = $baseurl . $data['photo'];
}
} }
} }
} }