Skip to content

Commit

Permalink
Don't populate the PHOTO property when it's not an image
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Apr 2, 2020
1 parent 04fad89 commit fabec4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 25 additions & 2 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,33 @@ protected function addChange($addressBookId, $objectUri, $operation) {

private function readBlob($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);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion apps/dav/lib/CardDAV/HasPhotoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function propFind(PropFind $propFind, INode $node) {
if ($node instanceof Card) {
$propFind->handle($ns . 'has-photo', function () use ($node) {
$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)
;
});
}
}
Expand Down

0 comments on commit fabec4c

Please sign in to comment.