From db80aae6119e95c900575b516817a0bdf91bc8fc Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 11 Dec 2023 17:08:43 +0545 Subject: [PATCH] Preserve backward-compatibility of client propFind --- lib/DAV/Client.php | 6 ++-- tests/Sabre/DAV/ClientTest.php | 51 ++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/DAV/Client.php b/lib/DAV/Client.php index 187b29ba37..1028a6b9d5 100644 --- a/lib/DAV/Client.php +++ b/lib/DAV/Client.php @@ -193,7 +193,7 @@ public function __construct(array $settings) * * @param 1|0 $depth */ - public function propFind(string $url, array $properties, int $depth = 0): array + public function propFind($url, array $properties, $depth = 0): array { $result = $this->doPropFind($url, $properties, $depth); @@ -265,7 +265,7 @@ public function propFindUnfiltered(string $url, array $properties, int $depth = * * @param 1|0 $depth */ - private function doPropFind(string $url, array $properties, int $depth = 0): array + private function doPropFind($url, array $properties, $depth = 0): array { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; @@ -441,7 +441,7 @@ public function getAbsoluteUrl($url) { return Uri\resolve( $this->baseUri, - $url + (string) $url ); } diff --git a/tests/Sabre/DAV/ClientTest.php b/tests/Sabre/DAV/ClientTest.php index e19ec07b44..cedecc0243 100644 --- a/tests/Sabre/DAV/ClientTest.php +++ b/tests/Sabre/DAV/ClientTest.php @@ -135,6 +135,41 @@ public function testPropFind() ], $request->getHeaders()); } + public function testPropFindWithIntegerUrl() + { + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = << + + + /123456 + + + bar + + HTTP/1.1 200 OK + + + +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propFind(123456, ['{DAV:}displayname', '{urn:zim}gir']); + + self::assertEquals(['{DAV:}displayname' => 'bar'], $result); + + $request = $client->request; + self::assertEquals('PROPFIND', $request->getMethod()); + self::assertEquals('/123456', $request->getUrl()); + self::assertEquals([ + 'Depth' => ['0'], + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); + } + public function testPropFindError() { $this->expectException('Sabre\HTTP\ClientHttpException'); @@ -146,7 +181,19 @@ public function testPropFindError() $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']); } - public function testPropFindDepth1() + public function depthProvider(): array + { + return [ + ['1'], + [1], + ]; + } + + /** + * @param int|string $depth + * @dataProvider depthProvider + */ + public function testPropFindDepth1($depth) { $client = new ClientMock([ 'baseUri' => '/', @@ -168,7 +215,7 @@ public function testPropFindDepth1() XML; $client->response = new Response(207, [], $responseBody); - $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], 1); + $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], $depth); self::assertEquals([ '/foo' => [