diff --git a/apps/dav/lib/Paginate/PaginatePlugin.php b/apps/dav/lib/Paginate/PaginatePlugin.php index b6d43461b1719..db00e463cd9f6 100644 --- a/apps/dav/lib/Paginate/PaginatePlugin.php +++ b/apps/dav/lib/Paginate/PaginatePlugin.php @@ -144,11 +144,6 @@ public function onMethod(RequestInterface $request, ResponseInterface $response) $items = $this->cache->get($url, $token, $offset, $count, $context); - $response->setStatus(207); - $response->addHeader(self::PAGINATE_HEADER, 'true'); - $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); - $response->setHeader('Vary', 'Brief,Prefer'); - // as we cached strings of XML, rebuild the multistatus response // and output the RAW entries, as stored in the cache $writer = $this->server->xml->getWriter(); @@ -157,11 +152,19 @@ public function onMethod(RequestInterface $request, ResponseInterface $response) $writer->startDocument(); $writer->startElement('{DAV:}multistatus'); foreach ($items as $item) { + if ($item === null) { + return; + } $writer->writeRaw($item); } $writer->endElement(); $writer->endDocument(); + $response->setStatus(207); + $response->addHeader(self::PAGINATE_HEADER, 'true'); + $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); + $response->setHeader('Vary', 'Brief,Prefer'); + $response->setBody($writer->flush()); return false; diff --git a/apps/dav/tests/unit/Paginate/PaginatePluginTest.php b/apps/dav/tests/unit/Paginate/PaginatePluginTest.php index 9e1058a2cf59e..636e6a8aa8833 100644 --- a/apps/dav/tests/unit/Paginate/PaginatePluginTest.php +++ b/apps/dav/tests/unit/Paginate/PaginatePluginTest.php @@ -304,6 +304,33 @@ public function testOnMethodPassesMinimalPreferenceInContext(): void { $this->plugin->onMethod($this->request, $this->response); } + public function testOnMethodIgnoresEvictedCacheEntries(): void { + $this->initializePlugin(); + + $this->request->method('hasHeader')->willReturn(true); + $this->request->method('getUrl')->willReturn('url'); + $this->request->method('getHeader')->willReturnMap([ + [PaginatePlugin::PAGINATE_TOKEN_HEADER, 'token'], + [PaginatePlugin::PAGINATE_OFFSET_HEADER, '0'], + [PaginatePlugin::PAGINATE_COUNT_HEADER, '2'], + ]); + + $this->cache->method('exists')->willReturn(true); + $this->cache->method('get')->willReturn((function (): \Generator { + yield $this->getResponseXmlForFile('/file1', 'File 1'); + yield null; + })()); + + $this->response->expects(self::never()) + ->method('setStatus'); + $this->response->expects(self::never()) + ->method('addHeader'); + $this->response->expects(self::never()) + ->method('setBody'); + + self::assertNull($this->plugin->onMethod($this->request, $this->response)); + } + public function testOnMultiStatusNoPaginateHeaderShouldSucceed(): void { $this->initializePlugin();