From 834991fed061e17438a5375891e50078f3c17847 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 12 Nov 2019 20:12:04 +0100 Subject: [PATCH] [stable17] update icewind/searchdav to 1.0.2 Signed-off-by: Daniel Kesselberg --- composer.json | 2 +- composer.lock | 14 ++++---- composer/installed.json | 14 ++++---- .../searchdav/src/Backend/ISearchBackend.php | 2 +- .../src/Backend/SearchPropertyDefinition.php | 2 +- .../searchdav/src/Backend/SearchResult.php | 2 +- icewind/searchdav/src/DAV/DiscoverHandler.php | 2 +- icewind/searchdav/src/DAV/PathHelper.php | 2 +- icewind/searchdav/src/DAV/QueryParser.php | 2 +- icewind/searchdav/src/DAV/SearchHandler.php | 33 +++++++++++-------- icewind/searchdav/src/DAV/SearchPlugin.php | 2 +- icewind/searchdav/src/Query/Limit.php | 2 +- icewind/searchdav/src/Query/Literal.php | 2 +- icewind/searchdav/src/Query/Operator.php | 4 +-- icewind/searchdav/src/Query/Order.php | 4 +-- icewind/searchdav/src/Query/Query.php | 6 ++-- icewind/searchdav/src/Query/Scope.php | 4 +-- icewind/searchdav/src/XML/BasicSearch.php | 4 +-- .../searchdav/src/XML/BasicSearchSchema.php | 2 +- icewind/searchdav/src/XML/Limit.php | 4 +-- icewind/searchdav/src/XML/Literal.php | 11 +++++-- icewind/searchdav/src/XML/Operator.php | 20 ++++++++--- icewind/searchdav/src/XML/Order.php | 6 ++-- icewind/searchdav/src/XML/PropDesc.php | 2 +- .../src/XML/QueryDiscoverResponse.php | 2 +- icewind/searchdav/src/XML/Scope.php | 4 +-- .../src/XML/SupportedQueryGrammar.php | 2 +- 27 files changed, 88 insertions(+), 68 deletions(-) diff --git a/composer.json b/composer.json index c886fc3ab..327180b9a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "deepdiver1975/TarStreamer": "v0.1.0", "doctrine/dbal": "2.9.2", "guzzlehttp/guzzle": "6.3.3", - "icewind/searchdav": "1.0.1", + "icewind/searchdav": "1.0.2", "icewind/streams": "v0.7.1", "interfasys/lognormalizer": "^v1.0", "jeremeamia/SuperClosure": "^2.4", diff --git a/composer.lock b/composer.lock index 0b3d482a4..0b5ffea74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "66fc7245784fcfe80b9bcdc46705ccb7", + "content-hash": "5e8eb95bea6dce42b7c8d28ada369474", "packages": [ { "name": "aws/aws-sdk-php", @@ -1329,20 +1329,20 @@ }, { "name": "icewind/searchdav", - "version": "v1.0.1", + "version": "v1.0.2", "source": { "type": "git", "url": "https://github.com/icewind1991/SearchDAV.git", - "reference": "b3fde1c79bc9c53f329f8ae1ee93d377903bf616" + "reference": "7174c023485c23037c6af786fce5a382fc72a75d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/icewind1991/SearchDAV/zipball/b3fde1c79bc9c53f329f8ae1ee93d377903bf616", - "reference": "b3fde1c79bc9c53f329f8ae1ee93d377903bf616", + "url": "https://api.github.com/repos/icewind1991/SearchDAV/zipball/7174c023485c23037c6af786fce5a382fc72a75d", + "reference": "7174c023485c23037c6af786fce5a382fc72a75d", "shasum": "" }, "require": { - "php": ">=5.6", + "php": ">=7.1", "sabre/dav": "^3.2.0" }, "require-dev": { @@ -1366,7 +1366,7 @@ } ], "description": "sabre/dav plugin to implement rfc5323 SEARCH", - "time": "2018-03-22T16:07:21+00:00" + "time": "2019-11-06T13:15:26+00:00" }, { "name": "icewind/streams", diff --git a/composer/installed.json b/composer/installed.json index 6f64a5fd0..6bb9a9ea8 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -1364,27 +1364,27 @@ }, { "name": "icewind/searchdav", - "version": "v1.0.1", - "version_normalized": "1.0.1.0", + "version": "v1.0.2", + "version_normalized": "1.0.2.0", "source": { "type": "git", "url": "https://github.com/icewind1991/SearchDAV.git", - "reference": "b3fde1c79bc9c53f329f8ae1ee93d377903bf616" + "reference": "7174c023485c23037c6af786fce5a382fc72a75d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/icewind1991/SearchDAV/zipball/b3fde1c79bc9c53f329f8ae1ee93d377903bf616", - "reference": "b3fde1c79bc9c53f329f8ae1ee93d377903bf616", + "url": "https://api.github.com/repos/icewind1991/SearchDAV/zipball/7174c023485c23037c6af786fce5a382fc72a75d", + "reference": "7174c023485c23037c6af786fce5a382fc72a75d", "shasum": "" }, "require": { - "php": ">=5.6", + "php": ">=7.1", "sabre/dav": "^3.2.0" }, "require-dev": { "phpunit/phpunit": "^4.8" }, - "time": "2018-03-22T16:07:21+00:00", + "time": "2019-11-06T13:15:26+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/icewind/searchdav/src/Backend/ISearchBackend.php b/icewind/searchdav/src/Backend/ISearchBackend.php index 665666cff..21d577b76 100644 --- a/icewind/searchdav/src/Backend/ISearchBackend.php +++ b/icewind/searchdav/src/Backend/ISearchBackend.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/Backend/SearchPropertyDefinition.php b/icewind/searchdav/src/Backend/SearchPropertyDefinition.php index d7de46a05..daa22bd36 100644 --- a/icewind/searchdav/src/Backend/SearchPropertyDefinition.php +++ b/icewind/searchdav/src/Backend/SearchPropertyDefinition.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/Backend/SearchResult.php b/icewind/searchdav/src/Backend/SearchResult.php index 32f99a7ec..43ee33343 100644 --- a/icewind/searchdav/src/Backend/SearchResult.php +++ b/icewind/searchdav/src/Backend/SearchResult.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/DAV/DiscoverHandler.php b/icewind/searchdav/src/DAV/DiscoverHandler.php index 675fd6a73..62fb5f8da 100644 --- a/icewind/searchdav/src/DAV/DiscoverHandler.php +++ b/icewind/searchdav/src/DAV/DiscoverHandler.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/DAV/PathHelper.php b/icewind/searchdav/src/DAV/PathHelper.php index de7ea6a03..b572493a9 100644 --- a/icewind/searchdav/src/DAV/PathHelper.php +++ b/icewind/searchdav/src/DAV/PathHelper.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/DAV/QueryParser.php b/icewind/searchdav/src/DAV/QueryParser.php index 592b62040..44c594b58 100644 --- a/icewind/searchdav/src/DAV/QueryParser.php +++ b/icewind/searchdav/src/DAV/QueryParser.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/DAV/SearchHandler.php b/icewind/searchdav/src/DAV/SearchHandler.php index ab400ce6e..8f6483e8b 100644 --- a/icewind/searchdav/src/DAV/SearchHandler.php +++ b/icewind/searchdav/src/DAV/SearchHandler.php @@ -1,4 +1,4 @@ - * @@ -62,11 +62,6 @@ public function handleSearchRequest($xml, ResponseInterface $response) { } /** @var BasicSearch $query */ $query = $xml['{DAV:}basicsearch']; - if (!$query->where) { - $response->setStatus(400); - $response->setBody('Parse error: Missing {DAV:}where from {DAV:}basicsearch'); - return false; - } if (!$query->select) { $response->setStatus(400); $response->setBody('Parse error: Missing {DAV:}select from {DAV:}basicsearch'); @@ -89,7 +84,8 @@ public function handleSearchRequest($xml, ResponseInterface $response) { $response->setBody($e->getMessage()); return false; } - $data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results, $query->select)), false); + $data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results, + $query->select)), false); $response->setBody($data); return false; } @@ -98,9 +94,10 @@ public function handleSearchRequest($xml, ResponseInterface $response) { * @param BasicSearch $xml * @param SearchPropertyDefinition[] $allProps * @return Query + * @throws BadRequest */ private function getQueryForXML(BasicSearch $xml, array $allProps) { - $orderBy = array_map(function(\SearchDAV\XML\Order $order) use ($allProps) { + $orderBy = array_map(function (\SearchDAV\XML\Order $order) use ($allProps) { if (!isset($allProps[$order->property])) { throw new BadRequest('requested order by property is not a valid property for this scope'); } @@ -110,7 +107,7 @@ private function getQueryForXML(BasicSearch $xml, array $allProps) { } return new Order($prop, $order->order); }, $xml->orderBy); - $select = array_map(function($propName) use ($allProps) { + $select = array_map(function ($propName) use ($allProps) { if (!isset($allProps[$propName])) { return; } @@ -122,13 +119,19 @@ private function getQueryForXML(BasicSearch $xml, array $allProps) { }, $xml->select); $select = array_filter($select); - $where = $this->transformOperator($xml->where, $allProps); + $where = $xml->where ? $this->transformOperator($xml->where, $allProps) : null; return new Query($select, $xml->from, $where, $orderBy, $xml->limit); } + /** + * @param \SearchDAV\XML\Operator $operator + * @param array $allProps + * @return Operator + * @throws BadRequest + */ private function transformOperator(\SearchDAV\XML\Operator $operator, array $allProps) { - $arguments = array_map(function($argument) use ($allProps) { + $arguments = array_map(function ($argument) use ($allProps) { if (is_string($argument)) { if (!isset($allProps[$argument])) { throw new BadRequest('requested search property is not a valid property for this scope'); @@ -138,10 +141,12 @@ private function transformOperator(\SearchDAV\XML\Operator $operator, array $all throw new BadRequest('requested search property is not searchable'); } return $prop; - } else if ($argument instanceof \SearchDAV\XML\Operator) { - return $this->transformOperator($argument, $allProps); } else { - return $argument; + if ($argument instanceof \SearchDAV\XML\Operator) { + return $this->transformOperator($argument, $allProps); + } else { + return $argument; + } } }, $operator->arguments); diff --git a/icewind/searchdav/src/DAV/SearchPlugin.php b/icewind/searchdav/src/DAV/SearchPlugin.php index 98c3ae913..113010baa 100644 --- a/icewind/searchdav/src/DAV/SearchPlugin.php +++ b/icewind/searchdav/src/DAV/SearchPlugin.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/Query/Limit.php b/icewind/searchdav/src/Query/Limit.php index 0619e0250..e6b4867ed 100644 --- a/icewind/searchdav/src/Query/Limit.php +++ b/icewind/searchdav/src/Query/Limit.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/Query/Literal.php b/icewind/searchdav/src/Query/Literal.php index 58b2fdd72..862a41249 100644 --- a/icewind/searchdav/src/Query/Literal.php +++ b/icewind/searchdav/src/Query/Literal.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/Query/Operator.php b/icewind/searchdav/src/Query/Operator.php index 868557bd7..198d1fbf0 100644 --- a/icewind/searchdav/src/Query/Operator.php +++ b/icewind/searchdav/src/Query/Operator.php @@ -1,4 +1,4 @@ - * @@ -60,7 +60,7 @@ class Operator { * @param string $type * @param array $arguments */ - public function __construct($type = '', array $arguments = []) { + public function __construct(string $type = '', array $arguments = []) { $this->type = $type; $this->arguments = $arguments; } diff --git a/icewind/searchdav/src/Query/Order.php b/icewind/searchdav/src/Query/Order.php index 52666582c..c6afceee6 100644 --- a/icewind/searchdav/src/Query/Order.php +++ b/icewind/searchdav/src/Query/Order.php @@ -1,4 +1,4 @@ - * @@ -46,7 +46,7 @@ class Order { * @param SearchPropertyDefinition $property * @param string $order */ - public function __construct(SearchPropertyDefinition $property, $order) { + public function __construct(SearchPropertyDefinition $property, string $order) { $this->property = $property; $this->order = $order; } diff --git a/icewind/searchdav/src/Query/Query.php b/icewind/searchdav/src/Query/Query.php index 85fc1edaf..613c3698d 100644 --- a/icewind/searchdav/src/Query/Query.php +++ b/icewind/searchdav/src/Query/Query.php @@ -1,4 +1,4 @@ - * @@ -65,11 +65,11 @@ class Query { * Query constructor. * @param SearchPropertyDefinition[] $select * @param Scope[] $from - * @param Operator $where + * @param Operator|null $where * @param Order[] $orderBy * @param Limit $limit */ - public function __construct(array $select, array $from, Operator $where, array $orderBy, Limit $limit) { + public function __construct(array $select, array $from, ?Operator $where, array $orderBy, Limit $limit) { $this->select = $select; $this->from = $from; $this->where = $where; diff --git a/icewind/searchdav/src/Query/Scope.php b/icewind/searchdav/src/Query/Scope.php index ebc778d45..9c342c85b 100644 --- a/icewind/searchdav/src/Query/Scope.php +++ b/icewind/searchdav/src/Query/Scope.php @@ -1,4 +1,4 @@ - * @@ -52,7 +52,7 @@ class Scope { * @param int|string $depth * @param string|null $path */ - public function __construct($href = '', $depth = 1, $path = null) { + public function __construct(string $href = '', $depth = 1, string $path = null) { $this->href = $href; $this->depth = $depth; $this->path = $path; diff --git a/icewind/searchdav/src/XML/BasicSearch.php b/icewind/searchdav/src/XML/BasicSearch.php index 8af30f4e8..269edb028 100644 --- a/icewind/searchdav/src/XML/BasicSearch.php +++ b/icewind/searchdav/src/XML/BasicSearch.php @@ -1,4 +1,4 @@ - * @@ -70,7 +70,7 @@ class BasicSearch implements XmlDeserializable { * @return BasicSearch * @throws ParseException */ - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): BasicSearch { $search = new self(); $elements = \Sabre\Xml\Deserializer\keyValue($reader); diff --git a/icewind/searchdav/src/XML/BasicSearchSchema.php b/icewind/searchdav/src/XML/BasicSearchSchema.php index 0e4c30d40..edda37295 100644 --- a/icewind/searchdav/src/XML/BasicSearchSchema.php +++ b/icewind/searchdav/src/XML/BasicSearchSchema.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/XML/Limit.php b/icewind/searchdav/src/XML/Limit.php index 0179d40db..26d7866d2 100644 --- a/icewind/searchdav/src/XML/Limit.php +++ b/icewind/searchdav/src/XML/Limit.php @@ -1,4 +1,4 @@ - * @@ -29,7 +29,7 @@ * The limit and offset of a search query */ class Limit extends \SearchDAV\Query\Limit implements XmlDeserializable { - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): Limit { $limit = new self(); $elements = \Sabre\Xml\Deserializer\keyValue($reader); diff --git a/icewind/searchdav/src/XML/Literal.php b/icewind/searchdav/src/XML/Literal.php index 03d167f3f..92c76ca56 100644 --- a/icewind/searchdav/src/XML/Literal.php +++ b/icewind/searchdav/src/XML/Literal.php @@ -1,4 +1,4 @@ - * @@ -26,10 +26,15 @@ use Sabre\Xml\XmlDeserializable; class Literal extends \SearchDAV\Query\Literal implements XmlDeserializable { - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): Literal { $literal = new self(); - $literal->value = $reader->readText(); + if ($reader->isEmptyElement) { + $literal->value = ''; + } else { + $literal->value = $reader->readText(); + } + $reader->read(); return $literal; diff --git a/icewind/searchdav/src/XML/Operator.php b/icewind/searchdav/src/XML/Operator.php index 6439ff662..61f410ab5 100644 --- a/icewind/searchdav/src/XML/Operator.php +++ b/icewind/searchdav/src/XML/Operator.php @@ -1,4 +1,4 @@ - * @@ -23,6 +23,7 @@ use Sabre\Xml\Reader; use Sabre\Xml\XmlDeserializable; +use SearchDAV\Query\Operator as QueryOperator; class Operator implements XmlDeserializable { /** @@ -50,12 +51,12 @@ class Operator implements XmlDeserializable { * @param string $type * @param array $arguments */ - public function __construct($type = '', array $arguments = []) { + public function __construct(string $type = '', array $arguments = []) { $this->type = $type; $this->arguments = $arguments; } - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): Operator { $operator = new self(); $operator->type = $reader->getClark(); @@ -63,17 +64,26 @@ static function xmlDeserialize(Reader $reader) { $reader->next(); return $operator; } + + if ($operator->type === QueryOperator::OPERATION_CONTAINS) { + $operator->arguments[] = $reader->readString(); + $reader->next(); + return $operator; + } + $reader->read(); do { if ($reader->nodeType === Reader::ELEMENT) { $argument = $reader->parseCurrentElement(); if ($argument['name'] === '{DAV:}prop') { - $operator->arguments[] = $argument['value'][0]; + $operator->arguments[] = $argument['value'][0] ?? ''; } else { $operator->arguments[] = $argument['value']; } } else { - $reader->read(); + if (!$reader->read()) { + break; + } } } while ($reader->nodeType !== Reader::END_ELEMENT); diff --git a/icewind/searchdav/src/XML/Order.php b/icewind/searchdav/src/XML/Order.php index 6573473fb..7aae16200 100644 --- a/icewind/searchdav/src/XML/Order.php +++ b/icewind/searchdav/src/XML/Order.php @@ -1,4 +1,4 @@ - * @@ -45,12 +45,12 @@ class Order implements XmlDeserializable { * @param string $property * @param string $order */ - public function __construct($property = '', $order = \SearchDAV\Query\Order::ASC) { + public function __construct(string $property = '', string $order = \SearchDAV\Query\Order::ASC) { $this->property = $property; $this->order = $order; } - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): Order { $order = new self(); $childs = \Sabre\Xml\Deserializer\keyValue($reader); diff --git a/icewind/searchdav/src/XML/PropDesc.php b/icewind/searchdav/src/XML/PropDesc.php index 85e0c6380..ab503b3f8 100644 --- a/icewind/searchdav/src/XML/PropDesc.php +++ b/icewind/searchdav/src/XML/PropDesc.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/XML/QueryDiscoverResponse.php b/icewind/searchdav/src/XML/QueryDiscoverResponse.php index b564b3b92..802fdcdab 100644 --- a/icewind/searchdav/src/XML/QueryDiscoverResponse.php +++ b/icewind/searchdav/src/XML/QueryDiscoverResponse.php @@ -1,4 +1,4 @@ - * diff --git a/icewind/searchdav/src/XML/Scope.php b/icewind/searchdav/src/XML/Scope.php index 905e140a6..78d4ba4e0 100644 --- a/icewind/searchdav/src/XML/Scope.php +++ b/icewind/searchdav/src/XML/Scope.php @@ -1,4 +1,4 @@ - * @@ -25,7 +25,7 @@ use Sabre\Xml\XmlDeserializable; class Scope extends \SearchDAV\Query\Scope implements XmlDeserializable { - static function xmlDeserialize(Reader $reader) { + static function xmlDeserialize(Reader $reader): Scope { $scope = new self(); $values = \Sabre\Xml\Deserializer\keyValue($reader); diff --git a/icewind/searchdav/src/XML/SupportedQueryGrammar.php b/icewind/searchdav/src/XML/SupportedQueryGrammar.php index 9b17a9ba0..ddb4e33e5 100644 --- a/icewind/searchdav/src/XML/SupportedQueryGrammar.php +++ b/icewind/searchdav/src/XML/SupportedQueryGrammar.php @@ -1,4 +1,4 @@ - *