Don't populate the PHOTO property when it's not an image

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-03-12 11:26:31 +01:00 committed by Georg Ehrke
parent bb754cb363
commit 648c8df516
No known key found for this signature in database
GPG Key ID: 9D98FD9380A1CB43
2 changed files with 31 additions and 3 deletions

View File

@ -874,10 +874,33 @@ class CardDavBackend implements BackendInterface, SyncSupport {
private function readBlob($cardData) { private function readBlob($cardData) {
if (is_resource($cardData)) { if (is_resource($cardData)) {
return stream_get_contents($cardData); $cardData = stream_get_contents($cardData);
} }
return $cardData; $cardDataArray = explode("\r\n", $cardData);
$cardDataFiltered = [];
$removingPhoto = false;
foreach ($cardDataArray as $line) {
if (strpos($line, 'PHOTO:data:') === 0
&& strpos($line, 'PHOTO:data:image/') !== 0) {
// Filter out PHOTO data of non-images
$removingPhoto = true;
continue;
}
if ($removingPhoto) {
if (strpos($line, ' ') === 0) {
continue;
}
// No leading space means this is a new property
$removingPhoto = false;
}
$cardDataFiltered[] = $line;
}
return implode("\r\n", $cardDataFiltered);
} }
/** /**

View File

@ -62,7 +62,12 @@ class HasPhotoPlugin extends ServerPlugin {
if ($node instanceof Card) { if ($node instanceof Card) {
$propFind->handle($ns . 'has-photo', function () use ($node) { $propFind->handle($ns . 'has-photo', function () use ($node) {
$vcard = Reader::read($node->get()); $vcard = Reader::read($node->get());
return ($vcard instanceof VCard && $vcard->PHOTO); return $vcard instanceof VCard
&& $vcard->PHOTO
// Either the PHOTO is a url (doesn't start with data:) or the mimetype has to start with image/
&& (strpos($vcard->PHOTO->getValue(), 'data:') !== 0
|| strpos($vcard->PHOTO->getValue(), 'data:image/') === 0)
;
}); });
} }
} }