aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorArne Hamann <kontakt+github@arne.email>2018-01-18 15:08:24 +0530
committerArne Hamann <kontakt+github@arne.email>2019-05-28 10:01:56 +0200
commit2c5ebac458f899af190d2ef7bf8702624e700049 (patch)
tree31540390a12c3f423279db1566b5da3ef6429299 /apps/dav/lib
parent633a1981428a1b94626ea6447c9ee305162c01dd (diff)
downloadnextcloud-server-2c5ebac458f899af190d2ef7bf8702624e700049.tar.gz
nextcloud-server-2c5ebac458f899af190d2ef7bf8702624e700049.zip
Allow to search for real pattern in contacts
Added an option escape_like_param to allow wildcards Signed-off-by: Arne Hamann <kontakt+github@arne.email>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CardDAV/AddressBookImpl.php8
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php10
2 files changed, 13 insertions, 5 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php
index ae727b8544f..b5dbbe59817 100644
--- a/apps/dav/lib/CardDAV/AddressBookImpl.php
+++ b/apps/dav/lib/CardDAV/AddressBookImpl.php
@@ -97,20 +97,22 @@ class AddressBookImpl implements IAddressBook {
/**
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
- * @param array $options Options to define the output format
- * - types boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
+ * @param array $options Options to define the output format and search behavior
+ * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
* example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
+ * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
* @return array an array of contacts which are arrays of key-value-pairs
* example result:
* [
* ['id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'],
* ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['d@e.f', 'g@h.i']]
* ]
+ * @param array $options = array() 'escape_like_param' - to not escape wildcards _ and % - for future use. One should always have options!
* @return array an array of contacts which are arrays of key-value-pairs
* @since 5.0.0
*/
public function search($pattern, $searchProperties, $options) {
- $results = $this->backend->search($this->getKey(), $pattern, $searchProperties);
+ $results = $this->backend->search($this->getKey(), $pattern, $searchProperties, $options = $options);
$withTypes = \array_key_exists('types', $options) && $options['types'] === true;
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index f30a12bba4e..ee9a790bc93 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -903,9 +903,11 @@ class CardDavBackend implements BackendInterface, SyncSupport {
* @param int $addressBookId
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
+ * @param array $options = array() to define the search behavior
+ * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are
* @return array an array of contacts which are arrays of key-value-pairs
*/
- public function search($addressBookId, $pattern, $searchProperties) {
+ public function search($addressBookId, $pattern, $searchProperties, $options = array()) {
$query = $this->db->getQueryBuilder();
$query2 = $this->db->getQueryBuilder();
@@ -919,7 +921,11 @@ class CardDavBackend implements BackendInterface, SyncSupport {
// No need for like when the pattern is empty
if ('' !== $pattern) {
- $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
+ if(\array_key_exists('escape_like_param', $options) && $options['escape_like_param'] === false) {
+ $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter($pattern)));
+ } else {
+ $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
+ }
}
$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')