Skip to content

Commit 075db3f

Browse files
committed
Allow URI as data for vcard PHOTO
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
1 parent c4a9bd1 commit 075db3f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

apps/dav/lib/CardDAV/PhotoCache.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\Files\SimpleFS\ISimpleFolder;
3131
use Sabre\CardDAV\Card;
3232
use Sabre\VObject\Property\Binary;
33+
use Sabre\VObject\Property\Uri;
3334
use Sabre\VObject\Reader;
3435

3536
class PhotoCache {
@@ -193,19 +194,23 @@ private function getPhoto(Card $node) {
193194
}
194195

195196
$photo = $vObject->PHOTO;
196-
$type = $this->getType($photo);
197-
198197
$val = $photo->getValue();
198+
199+
// handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE
199200
if ($photo->getValueType() === 'URI') {
200201
$parsed = \Sabre\URI\parse($val);
201-
//only allow data://
202+
203+
// only allow data://
202204
if ($parsed['scheme'] !== 'data') {
203205
return false;
204206
}
205207
if (substr_count($parsed['path'], ';') === 1) {
206208
list($type,) = explode(';', $parsed['path']);
207209
}
208210
$val = file_get_contents($val);
211+
} else {
212+
// get type if binary data
213+
$type = $this->getBinaryType($photo);
209214
}
210215

211216
$allowedContentTypes = [
@@ -240,7 +245,7 @@ private function readCard($cardData) {
240245
* @param Binary $photo
241246
* @return string
242247
*/
243-
private function getType(Binary $photo) {
248+
private function getBinaryType(Binary $photo) {
244249
$params = $photo->parameters();
245250
if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
246251
/** @var Parameter $typeParam */

0 commit comments

Comments
 (0)