Просмотр исходного кода

Fix regex search for tags (#6972)

https://github.com/FreshRSS/FreshRSS/issues/6949#issuecomment-2452363378
Alexandre Alapetite 1 год назад
Родитель
Сommit
df28324c34
2 измененных файлов с 6 добавлено и 1 удалено
  1. 1 1
      app/Models/BooleanSearch.php
  2. 5 0
      tests/app/Models/SearchTest.php

+ 1 - 1
app/Models/BooleanSearch.php

@@ -137,7 +137,7 @@ class FreshRSS_BooleanSearch {
 	 * Temporarily escape parentheses used in regex expressions.
 	 */
 	public static function escapeRegexParentheses(string $input): string {
-		return preg_replace_callback('#(?<=[\\s(:!-]|^)(?<![\\\\])/.+?(?<!\\\\)/[im]*#',
+		return preg_replace_callback('%(?<=[\\s(:#!-]|^)(?<![\\\\])/.+?(?<!\\\\)/[im]*%',
 			fn(array $matches): string => str_replace(['(', ')'], ['\\u0028', '\\u0029'], $matches[0]),
 			$input
 		) ?? '';

+ 5 - 0
tests/app/Models/SearchTest.php

@@ -525,6 +525,11 @@ class SearchTest extends PHPUnit\Framework\TestCase {
 				'(NOT e.title ~ ? AND NOT e.content ~ ? )',
 				['^ab$', '^ab$']
 			],
+			[
+				'#/^a(b|c)$/im',
+				"(REPLACE(REPLACE(e.tags, ' #', '#'), '#', '\n') ~* ? )",
+				['(?m)^a(b|c)$']
+			],
 			[	// Not a regex
 				'inurl:https://example.net/test/',
 				'(e.link LIKE ? )',