]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't populate the PHOTO property when it's not an image
authorJoas Schilling <coding@schilljs.com>
Thu, 12 Mar 2020 10:26:31 +0000 (11:26 +0100)
committerGeorg Ehrke <developer@georgehrke.com>
Wed, 15 Apr 2020 13:49:39 +0000 (15:49 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/lib/CardDAV/CardDavBackend.php
apps/dav/lib/CardDAV/HasPhotoPlugin.php

index 1f87ca5f7c1275d9e770dabbb3c5c016b12fad75..bfdf7e53f408f1b31cea16e4aed28ef5d249cf28 100644 (file)
@@ -874,10 +874,33 @@ class CardDavBackend implements BackendInterface, SyncSupport {
 
        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);
        }
 
        /**
index bb847e74a37676bdc171869aa2095b5eb7033fba..cf9d68e14a4edcfb0f9dd0406bea782dc5978e59 100644 (file)
@@ -62,7 +62,12 @@ class HasPhotoPlugin extends ServerPlugin {
                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)
+                               ;
                        });
                }
        }