diff options
author | Joas Schilling <coding@schilljs.com> | 2021-12-08 18:53:54 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-12-13 13:49:03 +0100 |
commit | 955c0d4885f8c49e2f3a464ba068f3a16c2f186f (patch) | |
tree | f4a2fbc79ea3984d4e003bc95392bceed7824651 | |
parent | 898c11c3b46ab746bf98174ba2f2bbf1f6ce2711 (diff) | |
download | nextcloud-server-955c0d4885f8c49e2f3a464ba068f3a16c2f186f.tar.gz nextcloud-server-955c0d4885f8c49e2f3a464ba068f3a16c2f186f.zip |
Convert strict_search to wildcard property and add psalm docs
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 1 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 2 | ||||
-rw-r--r-- | lib/private/ContactsManager.php | 15 | ||||
-rw-r--r-- | lib/public/Contacts/IManager.php | 6 | ||||
-rw-r--r-- | lib/public/IAddressBook.php | 3 |
5 files changed, 21 insertions, 6 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 1b74f329f1f..3db20cb4220 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -108,6 +108,7 @@ class AddressBookImpl implements IAddressBook { * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results * - 'wildcard' - Whether the search should use wildcards + * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options * @return array an array of contacts which are arrays of key-value-pairs * example result: * [ diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 403c4646e47..3e360fb2e41 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1025,6 +1025,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results * - 'wildcard' - Whether the search should use wildcards + * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options * @return array an array of contacts which are arrays of key-value-pairs */ public function search($addressBookId, $pattern, $searchProperties, $options = []): array { @@ -1056,6 +1057,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @param string $pattern * @param array $searchProperties * @param array $options + * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options * @return array */ private function searchByAddressBookIds(array $addressBookIds, diff --git a/lib/private/ContactsManager.php b/lib/private/ContactsManager.php index 557cf98c66b..937fb94a09a 100644 --- a/lib/private/ContactsManager.php +++ b/lib/private/ContactsManager.php @@ -42,8 +42,10 @@ class ContactsManager implements IManager { * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results - * - 'enumeration' - Whether user enumeration on system address book is allowed - * - 'fullmatch' - Whether matching on full detail in system address book is allowed + * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed + * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed + * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search + * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options * @return array an array of contacts which are arrays of key-value-pairs */ public function search($pattern, $searchProperties = [], $options = []) { @@ -51,6 +53,7 @@ class ContactsManager implements IManager { $result = []; foreach ($this->addressBooks as $addressBook) { $searchOptions = $options; + $strictSearch = array_key_exists('strict_search', $options) && $options['strict_search'] === true; if ($addressBook->isSystemAddressBook()) { $fullMatch = !\array_key_exists('fullmatch', $options) || $options['fullmatch'] !== false; @@ -58,7 +61,13 @@ class ContactsManager implements IManager { // Neither full match is allowed, so skip the system address book continue; } - $searchOptions['wildcard'] = !\array_key_exists('enumeration', $options) || $options['enumeration'] !== false; + if ($strictSearch) { + $searchOptions['wildcard'] = false; + } else { + $searchOptions['wildcard'] = !\array_key_exists('enumeration', $options) || $options['enumeration'] !== false; + } + } else { + $searchOptions['wildcard'] = !$strictSearch; } $r = $addressBook->search($pattern, $searchProperties, $searchOptions); diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php index 6d5f318cfa8..e9bdc01c060 100644 --- a/lib/public/Contacts/IManager.php +++ b/lib/public/Contacts/IManager.php @@ -93,8 +93,10 @@ interface IManager { * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results - * - 'enumeration' - Whether user enumeration on system address book is allowed - * - 'fullmatch' - Whether matching on full detail in system addresss book is allowed + * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed + * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system addresss book is allowed + * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search + * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options * @return array an array of contacts which are arrays of key-value-pairs * @since 6.0.0 */ diff --git a/lib/public/IAddressBook.php b/lib/public/IAddressBook.php index 738745376d3..4bb632ae070 100644 --- a/lib/public/IAddressBook.php +++ b/lib/public/IAddressBook.php @@ -67,7 +67,8 @@ namespace OCP { * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results - * - 'wildcard' - Whether the search should use wildcards + * - 'wildcard' - (since 23.0.0) Whether the search should use wildcards + * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options * @return array an array of contacts which are arrays of key-value-pairs * example result: * [ |