Skip to content

Commit

Permalink
Fix negated text-match on param-filter
Browse files Browse the repository at this point in the history
The negation applies to the individual text-match (i.e. the negated
text-match matches if a parameter string does not match the search
string). It does not apply to the entire param-filter (i.e. it does not
mean there must be NO property instance that matches the param filter,
it is sufficient if there is one that does not match).
  • Loading branch information
mstilkerich authored and phil-davis committed Feb 12, 2021
1 parent 171e367 commit 7820ac4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/CardDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,14 @@ protected function validateParamFilters(array $vProperties, array $filters, $tes
$filter['text-match']['collation'],
$filter['text-match']['match-type']
);
if ($filter['text-match']['negate-condition']) {
$success = !$success;
}
}
if ($success) {
break;
}
}
if ($filter['text-match']['negate-condition']) {
$success = !$success;
}
} // else

// There are two conditions where we can already determine whether
Expand Down
15 changes: 12 additions & 3 deletions tests/Sabre/CardDAV/ValidateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,24 @@ public function data()
$filter14['text-matches'][0]['negate-condition'] = true;

// Param filter with text
// Check there is a TEL;TYPE that contains WORK
$filter15 = $filter5;
$filter15['param-filters'][0]['text-match'] = [
'match-type' => 'contains',
'value' => 'WORK',
'collation' => 'i;octet',
'negate-condition' => false,
];

// Check if there is a TEL;TYPE that does not contain WORK
$filter16 = $filter15;
$filter16['param-filters'][0]['text-match']['negate-condition'] = true;

// Check there is a TEL;TYPE that does not contain OTHER
// All TEL properties with a TYPE parameter match this
$filterNoTelWithTypeOther = $filter16;
$filterNoTelWithTypeOther['param-filters'][0]['text-match']['value'] = 'OTHER';

// Param filter + text filter
$filter17 = $filter5;
$filter17['test'] = 'anyof';
Expand Down Expand Up @@ -179,7 +187,7 @@ public function data()
[$body1, [$filter6], 'anyof', false, 'TEL;FOO is not defined, so this should return false'],

[$body1, [$filter7], 'anyof', false, 'TEL;TYPE is defined, so this should return false'],
[$body1, [$filter8], 'anyof', true, 'TEL;TYPE is not defined, so this should return true'],
[$body1, [$filter8], 'anyof', true, 'TEL;FOO is not defined, so this should return true'],

// Combined parameters
[$body1, [$filter9], 'anyof', true],
Expand All @@ -192,8 +200,9 @@ public function data()
[$body1, [$filter14], 'anyof', true],

// Param filter with text-match
[$body1, [$filter15], 'anyof', true],
[$body1, [$filter16], 'anyof', false],
[$body1, [$filter15], 'anyof', true, 'TEL;TYPE with value WORK exists, so this should return true' ],
[$body1, [$filter16], 'anyof', true, 'Some TEL;TYPE that do not match WORK exist. Match result is inverted, so this should return true'],
[$body1, [$filterNoTelWithTypeOther], 'anyof', true, 'No TEL;TYPE contains OTHER. Match result is inverted, so this should return true'],

// Param filter + text filter
[$body1, [$filter17], 'anyof', true],
Expand Down

0 comments on commit 7820ac4

Please sign in to comment.