Delimit the subreddit filter with ~ so it actually runs

The pattern used # as its delimiter and excluded a literal # inside the character class, so PCRE
ended the pattern early and the match never fired. It read as the filter doing nothing. The unit
test missed it by asserting against a retyped copy of the regex rather than the one in the file,
which is the only version that matters.
This commit is contained in:
Gmer4Lfe
2026-08-09 22:55:29 -04:00
parent 07f679b2e7
commit c0da7d935d
+4 -1
View File
@@ -188,7 +188,10 @@ function vv_ai_web_degoog(string $q): ?array {
$rows = [];
foreach ($d['results'] ?? [] as $r) {
$url = (string)($r['url'] ?? '');
if (preg_match('#^https?://(?:[a-z0-9-]+\.)*reddit\.com/r/[^/?#]+/?$#i', $url)) continue;
// Delimited with ~, not #. The character class has to exclude a literal # (a fragment),
// and with # as the delimiter PCRE ends the pattern there and the match silently never
// fires — which is exactly what happened, and it looked like the filter doing nothing.
if (preg_match('~^https?://(?:[a-z0-9-]+\.)*reddit\.com/r/[^/?#]+/?$~i', $url)) continue;
$rows[] = ['title' => $r['title'] ?? '',
'url' => $url,
'snippet' => ($r['snippet'] ?? '') !== '' ? $r['snippet'] : ($r['content'] ?? '')];