Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Only wildcard search if enumeration is allowed
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Dec 13, 2021
commit 631b5fc64b3c61a683b2b595f2237b5dcd6adb59
1 change: 1 addition & 0 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function getDisplayName() {
* - '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
* @return array an array of contacts which are arrays of key-value-pairs
* example result:
* [
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ public function updateShares(IShareable $shareable, $add, $remove) {
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are
* - '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
* @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($addressBookId, $pattern, $searchProperties, $options = []): array {
Expand Down Expand Up @@ -1062,6 +1063,7 @@ private function searchByAddressBookIds(array $addressBookIds,
array $searchProperties,
array $options = []): array {
$escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
$useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false;

$query2 = $this->db->getQueryBuilder();

Expand Down Expand Up @@ -1103,7 +1105,9 @@ private function searchByAddressBookIds(array $addressBookIds,

// No need for like when the pattern is empty
if ('' !== $pattern) {
if (!$escapePattern) {
if (!$useWildcards) {
$query2->andWhere($query2->expr()->eq('cp.value', $query2->createNamedParameter($pattern)));
} elseif (!$escapePattern) {
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern)));
} else {
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
Expand Down
10 changes: 9 additions & 1 deletion lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$emailType = new SearchResultType('emails');

// Search in contacts
$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN'], ['limit' => $limit, 'offset' => $offset]);
$addressBookContacts = $this->contactsManager->search(
$search,
['EMAIL', 'FN'],
[
'limit' => $limit,
'offset' => $offset,
'wildcard' => $this->shareeEnumeration,
]
);
$lowerSearch = strtolower($search);
foreach ($addressBookContacts as $contact) {
if (isset($contact['EMAIL'])) {
Expand Down
1 change: 1 addition & 0 deletions lib/private/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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
* - 'wildcard' - Whether the search should use wildcards
* @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($pattern, $searchProperties = [], $options = []) {
Expand Down
1 change: 1 addition & 0 deletions lib/public/Contacts/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ 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
* - 'wildcard' - Whether the search should use wildcards
* @return array an array of contacts which are arrays of key-value-pairs
* @since 6.0.0
*/
Expand Down
1 change: 1 addition & 0 deletions lib/public/IAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function getDisplayName();
* - '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
* @return array an array of contacts which are arrays of key-value-pairs
* example result:
* [
Expand Down