Browse Source

Fix parenthesis escaping bug (#5633)

fix https://github.com/FreshRSS/FreshRSS/issues/5632
In the SQL search, parentheses should not be escaped. Escaped parenthesis in the SQL search were tolerated by PostgreSQL but not by SQLite.
Alexandre Alapetite 2 years ago
parent
commit
2e1d45a88d
3 changed files with 9 additions and 3 deletions
  1. 1 1
      app/Models/BooleanSearch.php
  2. 6 0
      app/Models/Search.php
  3. 2 2
      tests/app/Models/SearchTest.php

+ 1 - 1
app/Models/BooleanSearch.php

@@ -233,7 +233,7 @@ class FreshRSS_BooleanSearch {
 
 	private function parseOrSegments(string $input): void {
 		$input = trim($input);
-		if ($input == '') {
+		if ($input === '') {
 			return;
 		}
 		$splits = preg_split('/\b(OR)\b/i', $input, -1, PREG_SPLIT_DELIM_CAPTURE) ?: [];

+ 6 - 0
app/Models/Search.php

@@ -73,6 +73,7 @@ class FreshRSS_Search {
 
 	public function __construct(string $input) {
 		$input = self::cleanSearch($input);
+		$input = self::unescape($input);
 		$this->raw_input = $input;
 
 		$input = $this->parseNotEntryIds($input);
@@ -662,4 +663,9 @@ class FreshRSS_Search {
 		}
 		return trim($input);
 	}
+
+	/** Remove escaping backslashes for parenthesis logic */
+	private static function unescape(string $input): string {
+		return str_replace(['\\(', '\\)'], ['(', ')'], $input);
+	}
 }

+ 2 - 2
tests/app/Models/SearchTest.php

@@ -330,8 +330,8 @@ class SearchTest extends PHPUnit\Framework\TestCase {
 			[
 				'intitle:"\\(test\\)"',
 				'(e.title LIKE ? )',
-				['%\\(test\\)%'],
-			]
+				['%(test)%'],
+			],
 		];
 	}
 }