From 1a552bd60eab4a4b940d3896376b599e155d7da0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 6 Sep 2024 09:35:58 +0200 Subject: Regex search (#6706) * Regex search fix https://github.com/FreshRSS/FreshRSS/issues/3549 * Fix PHPStan * Fix escape * Fix ungreedy * Initial support for regex search in PostgreSQL and MySQL * Improvements, support MySQL * Fix multiline * Add support for SQLite * A few tests * Added author: and inurl: support, documentation * author example * Remove \b for now * Disable regex sanitization for now * Fix getInurlRegex * getNotInurlRegex * Quotes for inurl: * Fix test * Fix quoted tags + regex for tags https://github.com/FreshRSS/FreshRSS/issues/6761 * Fix wrong regex detection * Add MariaDB * Fix logic * Increase requirements for MySQL and MariaDB Check support for multiline mode in MySQL * Remove sanitizeRegexes() * Allow searching HTML code Allow searching for instance `/
/`
Fix https://github.com/FreshRSS/FreshRSS/issues/6775#issuecomment-2331769883

* Doc regex search HTML

* Fix Doctype
---
 app/Models/EntryDAOSQLite.php | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'app/Models/EntryDAOSQLite.php')

diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 9c2b37623..6d604f25a 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -28,6 +28,27 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
 		return str_replace('INSERT INTO ', 'INSERT OR IGNORE INTO ', $sql);
 	}
 
+	#[\Override]
+	protected static function sqlRegex(string $expression, string $regex, array &$values): string {
+		$values[] = $regex;
+		return "{$expression} REGEXP ?";
+	}
+
+	#[\Override]
+	protected function registerSqlFunctions(string $sql): void {
+		if (!str_contains($sql, ' REGEXP ')) {
+			return;
+		}
+		// https://php.net/pdo.sqlitecreatefunction
+		// https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators
+		$this->pdo->sqliteCreateFunction('regexp',
+			function (string $pattern, string $text): bool {
+				return preg_match($pattern, $text) === 1;
+			},
+			2
+		);
+	}
+
 	/** @param array $errorInfo */
 	#[\Override]
 	protected function autoUpdateDb(array $errorInfo): bool {
-- 
cgit v1.2.3