From 2c5abeb58d9d9a4fa5011eedb4e343288f2af50a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 9 Oct 2024 14:07:43 +0200 Subject: [PATCH] fix(PropFind): Include handle() props in d:allprop PROPFINDs Signed-off-by: provokateurin --- lib/DAV/PropFind.php | 18 +++++++++++++++++- tests/Sabre/DAV/PropFindTest.php | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/DAV/PropFind.php b/lib/DAV/PropFind.php index e9ffb07cbc..0df2eb5361 100644 --- a/lib/DAV/PropFind.php +++ b/lib/DAV/PropFind.php @@ -90,7 +90,23 @@ public function __construct($path, array $properties, $depth = 0, $requestType = */ public function handle($propertyName, $valueOrCallBack) { - if ($this->itemsLeft && isset($this->result[$propertyName]) && 404 === $this->result[$propertyName][0]) { + // If this is an ALLPROPS request and the property is + // unknown, add it to the result; else ignore it: + if (!isset($this->result[$propertyName])) { + if (self::ALLPROPS === $this->requestType) { + if (is_callable($valueOrCallBack)) { + $value = $valueOrCallBack(); + } else { + $value = $valueOrCallBack; + } + + $this->result[$propertyName] = [200, $value]; + } + + return; + } + + if ($this->itemsLeft && 404 === $this->result[$propertyName][0]) { if (is_callable($valueOrCallBack)) { $value = $valueOrCallBack(); } else { diff --git a/tests/Sabre/DAV/PropFindTest.php b/tests/Sabre/DAV/PropFindTest.php index ffbd4e493f..be3c4eb62b 100644 --- a/tests/Sabre/DAV/PropFindTest.php +++ b/tests/Sabre/DAV/PropFindTest.php @@ -52,9 +52,13 @@ public function testSetAllpropCustom() { $propFind = new PropFind('foo', ['{DAV:}displayname'], 0, PropFind::ALLPROPS); $propFind->set('{DAV:}customproperty', 'bar'); + $propFind->handle('{DAV:}otherproperty', fn () => 'baz'); self::assertEquals([ - 200 => ['{DAV:}customproperty' => 'bar'], + 200 => [ + '{DAV:}customproperty' => 'bar', + '{DAV:}otherproperty' => 'baz', + ], ], $propFind->getResultForMultiStatus()); }