Skip to content

Commit 505e905

Browse files
mstilkerichphil-davis
authored andcommitted
Fix negated text-match in prop-filter
The negate-condition attribute applies to the individual text-match, not the result of applying the non-negated match against all property instances of the asked for type.
1 parent 7820ac4 commit 505e905

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/CardDAV/Plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,15 @@ protected function validateTextMatches(array $texts, array $filters, $test)
635635
$success = false;
636636
foreach ($texts as $haystack) {
637637
$success = DAV\StringUtil::textMatch($haystack, $filter['value'], $filter['collation'], $filter['match-type']);
638+
if ($filter['negate-condition']) {
639+
$success = !$success;
640+
}
638641

639642
// Breaking on the first match
640643
if ($success) {
641644
break;
642645
}
643646
}
644-
if ($filter['negate-condition']) {
645-
$success = !$success;
646-
}
647647

648648
if ($success && 'anyof' === $test) {
649649
return true;

tests/Sabre/CardDAV/ValidateFilterTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public function data()
133133
$filter14['text-matches'][0]['value'] = 'bing';
134134
$filter14['text-matches'][0]['negate-condition'] = true;
135135

136+
// Check if there is an EMAIL address that does not have the 111.com domain
137+
$filterEmailWithoutSpecificDomain = $filter11;
138+
$filterEmailWithoutSpecificDomain['name'] = 'email';
139+
$filterEmailWithoutSpecificDomain['text-matches'][0]['value'] = '@111.com';
140+
$filterEmailWithoutSpecificDomain['text-matches'][0]['negate-condition'] = true;
141+
136142
// Param filter with text
137143
// Check there is a TEL;TYPE that contains WORK
138144
$filter15 = $filter5;
@@ -154,6 +160,9 @@ public function data()
154160

155161
// Param filter + text filter
156162
$filter17 = $filter5;
163+
164+
// Matches if the VCard contains a TEL property that either has a TYPE property defined (-> true),
165+
// or that has a value containing 444 (true)
157166
$filter17['test'] = 'anyof';
158167
$filter17['text-matches'][] = [
159168
'match-type' => 'contains',
@@ -162,6 +171,8 @@ public function data()
162171
'negate-condition' => false,
163172
];
164173

174+
// Matches if the VCard contains a TEL property that has a TYPE property defined
175+
// AND that has a value NOT containing 444 -> there is 3 properties matching these criteria
165176
$filter18 = $filter17;
166177
$filter18['text-matches'][0]['negate-condition'] = true;
167178

@@ -198,6 +209,7 @@ public function data()
198209
[$body1, [$filter12], 'anyof', false],
199210
[$body1, [$filter13], 'anyof', false],
200211
[$body1, [$filter14], 'anyof', true],
212+
[$body1, [$filterEmailWithoutSpecificDomain], 'anyof', true, "EMAIL properties with other domain exists, so this should return true"],
201213

202214
// Param filter with text-match
203215
[$body1, [$filter15], 'anyof', true, 'TEL;TYPE with value WORK exists, so this should return true' ],
@@ -206,8 +218,7 @@ public function data()
206218

207219
// Param filter + text filter
208220
[$body1, [$filter17], 'anyof', true],
209-
[$body1, [$filter18], 'anyof', false],
210-
[$body1, [$filter18], 'anyof', false],
221+
[$body1, [$filter18], 'anyof', true],
211222
];
212223
}
213224
}

0 commit comments

Comments
 (0)