fossar / selfoss

multipurpose rss reader, live stream, mashup, aggregation web application
https://selfoss.aditu.de
GNU General Public License v3.0
2.35k stars 343 forks source link

Bug in filter #1349

Closed heull001 closed 1 year ago

heull001 commented 1 year ago

helpers/src/ContentLoader.php line 336ff: if ($resultTitle === 0 && $resultContent === 0) { return false; }

I think, this should be ||. Otherwise users have to build a filter-expression, which works for the title and the content, I don't think, this is right.

jtojnar commented 1 year ago

The filter method returning false will cause the item to be skipped:

https://github.com/fossar/selfoss/blob/8dc7f1f489140ac108547966a510dd271f2b5c42/src/helpers/ContentLoader.php#L202-L204

That only happens when neither the title or the the content matches the filter (the line you point to):

https://github.com/fossar/selfoss/blob/8dc7f1f489140ac108547966a510dd271f2b5c42/src/helpers/ContentLoader.php#L337

Equivalently, the method could be written as:

    protected function filter($source, $title, $content) {
        if (strlen(trim($source['filter'])) === 0) {
            return false
        }

        $resultTitle = @preg_match($source['filter'], $title);
        $resultContent = @preg_match($source['filter'], $content);
        if ($resultTitle === false || $resultContent === false) {
            $this->logger->error('filter error: ' . $source['filter']);

            return true; // do not filter out item
        }
        // test filter
        if ($resultTitle !== 0 || $resultContent !== 0) {
            return true;
        }

        return false;
    }