aboutsummaryrefslogtreecommitdiff
path: root/app/Models/BooleanSearch.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/BooleanSearch.php')
-rw-r--r--app/Models/BooleanSearch.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php
index 10c2321fb..749dbdfa5 100644
--- a/app/Models/BooleanSearch.php
+++ b/app/Models/BooleanSearch.php
@@ -37,6 +37,7 @@ class FreshRSS_BooleanSearch {
if ($level === 0) {
$input = $this->parseUserQueryNames($input, $allowUserQueries);
$input = $this->parseUserQueryIds($input, $allowUserQueries);
+ $input = self::escapeRegexParentheses($input);
$input = trim($input);
}
@@ -133,6 +134,20 @@ class FreshRSS_BooleanSearch {
}
/**
+ * Temporarily escape parentheses used in regex expressions.
+ */
+ public static function escapeRegexParentheses(string $input): string {
+ return preg_replace_callback('#(?<=[\\s(:!-]|^)(?<![\\\\])/.*?(?<!\\\\)/[im]*#',
+ fn(array $matches): string => str_replace(['(', ')'], ['\\u0028', '\\u0029'], $matches[0]),
+ $input
+ ) ?? '';
+ }
+
+ public static function unescapeRegexParentheses(string $input): string {
+ return str_replace(['\\u0028', '\\u0029'], ['(', ')'], $input);
+ }
+
+ /**
* Example: 'ab cd OR ef OR "gh ij"' becomes '(ab cd) OR (ef) OR ("gh ij")'
*/
public static function addOrParentheses(string $input): string {