From 58de38bd737d2dba617944b54a98d4bdb5810588 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 1 Aug 2024 19:44:58 +0200 Subject: Fix parentheses for complex `OR` boolean search expressions (#6672) * Fix OR parentheses * Pass all tests * Forgotten comment * Minor whitespace * Fix several cases envolving negation * Line length * Fix `OR NOT` --- app/Models/Entry.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index e4d728ba4..ada6e9944 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -577,12 +577,20 @@ HTML; foreach ($booleanSearch->searches() as $filter) { if ($filter instanceof FreshRSS_BooleanSearch) { // BooleanSearches are combined by AND (default) or OR or AND NOT (special cases) operators and are recursive - if ($filter->operator() === 'OR') { - $ok |= $this->matches($filter); - } elseif ($filter->operator() === 'AND NOT') { - $ok &= !$this->matches($filter); - } else { // AND - $ok &= $this->matches($filter); + switch ($filter->operator()) { + case 'OR': + $ok |= $this->matches($filter); + break; + case 'OR NOT': + $ok |= !$this->matches($filter); + break; + case 'AND NOT': + $ok &= !$this->matches($filter); + break; + case 'AND': + default: + $ok &= $this->matches($filter); + break; } } elseif ($filter instanceof FreshRSS_Search) { // Searches are combined by OR and are not recursive -- cgit v1.2.3