aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-12-05 16:19:57 +0100
committerGravatar GitHub <noreply@github.com> 2024-12-05 16:19:57 +0100
commit3b15f8a5c9c919235c34518d14d09b41cfb93884 (patch)
tree31678e94b161903e236dff5870962081f017ded5 /app
parent84642037350393625f0a4866ed74f564ef37973b (diff)
Parentheses in quoted search (#7055)
* Parentheses in quoted search Allow parentheses in quoted search like `author:"Bob (Team1)"` Related to https://github.com/FreshRSS/FreshRSS/pull/7054 * Doc
Diffstat (limited to 'app')
-rw-r--r--app/Models/BooleanSearch.php14
-rw-r--r--app/Models/Search.php2
2 files changed, 8 insertions, 8 deletions
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php
index 375705036..529bcd338 100644
--- a/app/Models/BooleanSearch.php
+++ b/app/Models/BooleanSearch.php
@@ -39,7 +39,7 @@ class FreshRSS_BooleanSearch implements \Stringable {
$this->raw_input = $input;
if ($level === 0) {
- $input = self::escapeRegexParentheses($input);
+ $input = self::escapeLiteralParentheses($input);
$input = $this->parseUserQueryNames($input, $allowUserQueries);
$input = $this->parseUserQueryIds($input, $allowUserQueries);
$input = trim($input);
@@ -83,7 +83,7 @@ class FreshRSS_BooleanSearch implements \Stringable {
if (!empty($queries[$name])) {
$fromS[] = $matches[0][$i];
if ($allowUserQueries) {
- $toS[] = '(' . self::escapeRegexParentheses($queries[$name]) . ')';
+ $toS[] = '(' . self::escapeLiteralParentheses($queries[$name]) . ')';
} else {
$toS[] = '';
}
@@ -124,7 +124,7 @@ class FreshRSS_BooleanSearch implements \Stringable {
if (!empty($queries[$id])) {
$fromS[] = $matches[0][$i];
if ($allowUserQueries) {
- $toS[] = '(' . self::escapeRegexParentheses($queries[$id]) . ')';
+ $toS[] = '(' . self::escapeLiteralParentheses($queries[$id]) . ')';
} else {
$toS[] = '';
}
@@ -138,16 +138,16 @@ class FreshRSS_BooleanSearch implements \Stringable {
}
/**
- * Temporarily escape parentheses used in regex expressions.
+ * Temporarily escape parentheses used in regex expressions or inside quoted strings.
*/
- public static function escapeRegexParentheses(string $input): string {
- return preg_replace_callback('%(?<=[\\s(:#!-]|^)(?<![\\\\])/.+?(?<!\\\\)/[im]*%',
+ public static function escapeLiteralParentheses(string $input): string {
+ return preg_replace_callback('%(?<=[\\s(:#!-]|^)(?<![\\\\])(?P<delim>[\'"/]).+?(?<!\\\\)(?P=delim)[im]*%',
fn(array $matches): string => str_replace(['(', ')'], ['\\u0028', '\\u0029'], $matches[0]),
$input
) ?? '';
}
- public static function unescapeRegexParentheses(string $input): string {
+ public static function unescapeLiteralParentheses(string $input): string {
return str_replace(['\\u0028', '\\u0029'], ['(', ')'], $input);
}
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 4a006c2d0..a887ec2f7 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -94,7 +94,7 @@ class FreshRSS_Search implements \Stringable {
public function __construct(string $input) {
$input = self::cleanSearch($input);
$input = self::unescape($input);
- $input = FreshRSS_BooleanSearch::unescapeRegexParentheses($input);
+ $input = FreshRSS_BooleanSearch::unescapeLiteralParentheses($input);
$this->raw_input = $input;
$input = $this->parseNotEntryIds($input);