Skip to content

Commit

Permalink
Fix BadFunctionCall Exception in Nextcloud 26
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Apr 27, 2023
1 parent e731dfe commit ee9833d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Dav/Faces/FacePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public function getLastModified() {
return $this->getFile()->getMTime();
}

public function getMetadata(): array {
public function getMetadata(): string {
$file = $this->getFile();
$sizeMetadata = $this->metadataManager->fetchMetadataFor('size', [$file->getId()])[$file->getId()];
return $sizeMetadata->getMetadata();
return $sizeMetadata->getValue();

This comment has been minimized.

Copy link
@umgfoin

umgfoin Apr 27, 2023

I'd suggest to check for an empty or invalid JSON-string and return "{}" in case.
This would prevent any subsequent call to JSON.parse from failing on empty getValue() results.

$sizeMetadataJSON = $sizeMetadata->getValue();
return ($sizeMetadataJSON && strlen($sizeMetadataJSON) > 1) ? $sizeMetadataJSON : "{}";
}

public function hasPreview(): bool {
Expand Down
2 changes: 1 addition & 1 deletion lib/Dav/Faces/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function propFind(PropFind $propFind, INode $node) {
$propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn () => $node->getFile()->getId());
$propFind->handle(self::FILE_NAME_PROPERTYNAME, fn () => $node->getFile()->getName());
$propFind->handle(self::REALPATH_PROPERTYNAME, fn () => $node->getFile()->getPath());
$propFind->handle(FilesPlugin::FILE_METADATA_SIZE, fn () => json_encode($node->getMetadata()));
$propFind->handle(FilesPlugin::FILE_METADATA_SIZE, fn () => $node->getMetadata());
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($node->hasPreview()));
$propFind->handle(TagsPlugin::FAVORITE_PROPERTYNAME, fn () => $node->isFavorite() ? 1 : 0);
}
Expand Down

0 comments on commit ee9833d

Please sign in to comment.