Ver Fonte

Fix more overlapping search replacements (#9524)

Follow-up of https://github.com/FreshRSS/FreshRSS/pull/9484
The proposed construct is good enough compared to the previous TODO suggesting `PREG_OFFSET_CAPTURE`
Alexandre Alapetite há 21 horas atrás
pai
commit
6a640623d1
2 ficheiros alterados com 86 adições e 57 exclusões
  1. 55 57
      app/Models/Search.php
  2. 31 0
      tests/app/Models/SearchTest.php

+ 55 - 57
app/Models/Search.php

@@ -766,7 +766,7 @@ class FreshRSS_Search implements \Stringable {
 	 */
 	 */
 	private function parseEntryIds(string $input): string {
 	private function parseEntryIds(string $input): string {
 		if (preg_match_all('/\\be:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/\\be:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->entry_ids = [];
 			$this->entry_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -782,7 +782,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotEntryIds(string $input): string {
 	private function parseNotEntryIds(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]e:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]e:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->not_entry_ids = [];
 			$this->not_entry_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -798,7 +798,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseFeedIds(string $input): string {
 	private function parseFeedIds(string $input): string {
 		if (preg_match_all('/\\bf:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bf:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->feed_ids = [];
 			$this->feed_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -816,7 +816,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotFeedIds(string $input): string {
 	private function parseNotFeedIds(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]f:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]f:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->not_feed_ids = [];
 			$this->not_feed_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -834,7 +834,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseCategoryIds(string $input): string {
 	private function parseCategoryIds(string $input): string {
 		if (preg_match_all('/\\bc:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bc:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->category_ids = [];
 			$this->category_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -852,7 +852,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotCategoryIds(string $input): string {
 	private function parseNotCategoryIds(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]c:(?P<search>[0-9,]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]c:(?P<search>[0-9,]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->not_category_ids = [];
 			$this->not_category_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -972,7 +972,7 @@ class FreshRSS_Search implements \Stringable {
 	 */
 	 */
 	private function parseLabelIds(string $input): string {
 	private function parseLabelIds(string $input): string {
 		if (preg_match_all('/\\b[lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
 		if (preg_match_all('/\\b[lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->label_ids = [];
 			$this->label_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -994,7 +994,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotLabelIds(string $input): string {
 	private function parseNotLabelIds(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-][lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-][lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$ids_lists = $matches['search'];
 			$ids_lists = $matches['search'];
 			$this->not_label_ids = [];
 			$this->not_label_ids = [];
 			foreach ($ids_lists as $ids_list) {
 			foreach ($ids_lists as $ids_list) {
@@ -1021,11 +1021,11 @@ class FreshRSS_Search implements \Stringable {
 		$names_lists = [];
 		$names_lists = [];
 		if (preg_match_all('/\\blabels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/\\blabels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$names_lists = $matches['search'];
 			$names_lists = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\blabels?:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/\\blabels?:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$names_lists = array_merge($names_lists, $matches['search']);
 			$names_lists = array_merge($names_lists, $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (!empty($names_lists)) {
 		if (!empty($names_lists)) {
 			$this->label_names = [];
 			$this->label_names = [];
@@ -1047,11 +1047,11 @@ class FreshRSS_Search implements \Stringable {
 		$names_lists = [];
 		$names_lists = [];
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]labels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]labels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$names_lists = $matches['search'];
 			$names_lists = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]labels?:(?P<search>[^\\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]labels?:(?P<search>[^\\s"]*)/', $input, $matches)) {
 			$names_lists = array_merge($names_lists, $matches['search']);
 			$names_lists = array_merge($names_lists, $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (!empty($names_lists)) {
 		if (!empty($names_lists)) {
 			$this->not_label_names = [];
 			$this->not_label_names = [];
@@ -1072,15 +1072,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseIntitleSearch(string $input): string {
 	private function parseIntitleSearch(string $input): string {
 		if (preg_match_all('#\\bintitle:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#\\bintitle:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->intitle_regex = $matches['search'];
 			$this->intitle_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bintitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/\\bintitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->intitle = $matches['search'];
 			$this->intitle = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bintitle:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bintitle:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->intitle = array_merge($this->intitle ?? [], $matches['search']);
 			$this->intitle = array_merge($this->intitle ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->intitle = self::removeEmptyValues($this->intitle);
 		$this->intitle = self::removeEmptyValues($this->intitle);
 		if (empty($this->intitle)) {
 		if (empty($this->intitle)) {
@@ -1092,15 +1092,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseNotIntitleSearch(string $input): string {
 	private function parseNotIntitleSearch(string $input): string {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]intitle:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]intitle:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->not_intitle_regex = $matches['search'];
 			$this->not_intitle_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_intitle = $matches['search'];
 			$this->not_intitle = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intitle:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intitle:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->not_intitle = array_merge($this->not_intitle ?? [], $matches['search']);
 			$this->not_intitle = array_merge($this->not_intitle ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_intitle = self::removeEmptyValues($this->not_intitle);
 		$this->not_intitle = self::removeEmptyValues($this->not_intitle);
 		if (empty($this->not_intitle)) {
 		if (empty($this->not_intitle)) {
@@ -1115,15 +1115,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseIntextSearch(string $input): string {
 	private function parseIntextSearch(string $input): string {
 		if (preg_match_all('#\\bintext:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#\\bintext:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->intext_regex = $matches['search'];
 			$this->intext_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bintext:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/\\bintext:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->intext = $matches['search'];
 			$this->intext = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bintext:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bintext:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->intext = array_merge($this->intext ?? [], $matches['search']);
 			$this->intext = array_merge($this->intext ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->intext = self::removeEmptyValues($this->intext);
 		$this->intext = self::removeEmptyValues($this->intext);
 		if (empty($this->intext)) {
 		if (empty($this->intext)) {
@@ -1135,15 +1135,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseNotIntextSearch(string $input): string {
 	private function parseNotIntextSearch(string $input): string {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]intext:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]intext:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->not_intext_regex = $matches['search'];
 			$this->not_intext_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intext:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intext:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_intext = $matches['search'];
 			$this->not_intext = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intext:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]intext:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->not_intext = array_merge($this->not_intext ?? [], $matches['search']);
 			$this->not_intext = array_merge($this->not_intext ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_intext = self::removeEmptyValues($this->not_intext);
 		$this->not_intext = self::removeEmptyValues($this->not_intext);
 		if (empty($this->not_intext)) {
 		if (empty($this->not_intext)) {
@@ -1160,15 +1160,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseAuthorSearch(string $input): string {
 	private function parseAuthorSearch(string $input): string {
 		if (preg_match_all('#\\bauthor:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#\\bauthor:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->author_regex = $matches['search'];
 			$this->author_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bauthor:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/\\bauthor:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->author = $matches['search'];
 			$this->author = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\bauthor:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bauthor:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->author = array_merge($this->author ?? [], $matches['search']);
 			$this->author = array_merge($this->author ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->author = self::removeEmptyValues($this->author);
 		$this->author = self::removeEmptyValues($this->author);
 		if (empty($this->author)) {
 		if (empty($this->author)) {
@@ -1180,15 +1180,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseNotAuthorSearch(string $input): string {
 	private function parseNotAuthorSearch(string $input): string {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]author:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]author:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->not_author_regex = $matches['search'];
 			$this->not_author_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_author = $matches['search'];
 			$this->not_author = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]author:(?P<search>[^\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]author:(?P<search>[^\s"]*)/', $input, $matches)) {
 			$this->not_author = array_merge($this->not_author ?? [], $matches['search']);
 			$this->not_author = array_merge($this->not_author ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_author = self::removeEmptyValues($this->not_author);
 		$this->not_author = self::removeEmptyValues($this->not_author);
 		if (empty($this->not_author)) {
 		if (empty($this->not_author)) {
@@ -1204,15 +1204,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseInurlSearch(string $input): string {
 	private function parseInurlSearch(string $input): string {
 		if (preg_match_all('#\\binurl:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#\\binurl:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->inurl_regex = $matches['search'];
 			$this->inurl_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\binurl:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/\\binurl:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->inurl = $matches['search'];
 			$this->inurl = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/\\binurl:(?P<search>[^\\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/\\binurl:(?P<search>[^\\s"]*)/', $input, $matches)) {
 			$this->inurl = array_merge($this->inurl ?? [], $matches['search']);
 			$this->inurl = array_merge($this->inurl ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->inurl = self::removeEmptyValues($this->inurl);
 		$this->inurl = self::removeEmptyValues($this->inurl);
 		if (empty($this->inurl)) {
 		if (empty($this->inurl)) {
@@ -1224,15 +1224,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseNotInurlSearch(string $input): string {
 	private function parseNotInurlSearch(string $input): string {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]inurl:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-]inurl:(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->not_inurl_regex = $matches['search'];
 			$this->not_inurl_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]inurl:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]inurl:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_inurl = $matches['search'];
 			$this->not_inurl = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]inurl:(?P<search>[^\\s"]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]inurl:(?P<search>[^\\s"]*)/', $input, $matches)) {
 			$this->not_inurl = array_merge($this->not_inurl ?? [], $matches['search']);
 			$this->not_inurl = array_merge($this->not_inurl ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_inurl = self::removeEmptyValues($this->not_inurl);
 		$this->not_inurl = self::removeEmptyValues($this->not_inurl);
 		if (empty($this->not_inurl)) {
 		if (empty($this->not_inurl)) {
@@ -1247,7 +1247,7 @@ class FreshRSS_Search implements \Stringable {
 	 */
 	 */
 	private function parseDateSearch(string $input): string {
 	private function parseDateSearch(string $input): string {
 		if (preg_match_all('/\\bdate:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bdate:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->min_date, $this->max_date] = parseDateInterval($dates[0]);
 				[$this->min_date, $this->max_date] = parseDateInterval($dates[0]);
@@ -1261,7 +1261,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotDateSearch(string $input): string {
 	private function parseNotDateSearch(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]date:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]date:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->not_min_date, $this->not_max_date] = parseDateInterval($dates[0]);
 				[$this->not_min_date, $this->not_max_date] = parseDateInterval($dates[0]);
@@ -1280,7 +1280,7 @@ class FreshRSS_Search implements \Stringable {
 	 */
 	 */
 	private function parsePubdateSearch(string $input): string {
 	private function parsePubdateSearch(string $input): string {
 		if (preg_match_all('/\\bpubdate:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/\\bpubdate:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->min_pubdate, $this->max_pubdate] = parseDateInterval($dates[0]);
 				[$this->min_pubdate, $this->max_pubdate] = parseDateInterval($dates[0]);
@@ -1294,7 +1294,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotPubdateSearch(string $input): string {
 	private function parseNotPubdateSearch(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]pubdate:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]pubdate:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->not_min_pubdate, $this->not_max_pubdate] = parseDateInterval($dates[0]);
 				[$this->not_min_pubdate, $this->not_max_pubdate] = parseDateInterval($dates[0]);
@@ -1308,7 +1308,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseModifiedDateSearch(string $input): string {
 	private function parseModifiedDateSearch(string $input): string {
 		if (preg_match_all('/\bmdate:(?P<search>[^\s]*)/', $input, $matches)) {
 		if (preg_match_all('/\bmdate:(?P<search>[^\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->min_modified_date, $this->max_modified_date] = parseDateInterval($dates[0]);
 				[$this->min_modified_date, $this->max_modified_date] = parseDateInterval($dates[0]);
@@ -1322,7 +1322,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotModifiedDateSearch(string $input): string {
 	private function parseNotModifiedDateSearch(string $input): string {
 		if (preg_match_all('/(?<=[\s(]|^)[!-]mdate:(?P<search>[^\s]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\s(]|^)[!-]mdate:(?P<search>[^\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->not_min_modified_date, $this->not_max_modified_date] = parseDateInterval($dates[0]);
 				[$this->not_min_modified_date, $this->not_max_modified_date] = parseDateInterval($dates[0]);
@@ -1340,7 +1340,7 @@ class FreshRSS_Search implements \Stringable {
 	 */
 	 */
 	private function parseUserdateSearch(string $input): string {
 	private function parseUserdateSearch(string $input): string {
 		if (preg_match_all('/\\buserdate:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/\\buserdate:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->min_userdate, $this->max_userdate] = parseDateInterval($dates[0]);
 				[$this->min_userdate, $this->max_userdate] = parseDateInterval($dates[0]);
@@ -1354,7 +1354,7 @@ class FreshRSS_Search implements \Stringable {
 
 
 	private function parseNotUserdateSearch(string $input): string {
 	private function parseNotUserdateSearch(string $input): string {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]userdate:(?P<search>[^\\s]*)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]userdate:(?P<search>[^\\s]*)/', $input, $matches)) {
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 			$dates = self::removeEmptyValues($matches['search']);
 			$dates = self::removeEmptyValues($matches['search']);
 			if (!empty($dates[0])) {
 			if (!empty($dates[0])) {
 				[$this->not_min_userdate, $this->not_max_userdate] = parseDateInterval($dates[0]);
 				[$this->not_min_userdate, $this->not_max_userdate] = parseDateInterval($dates[0]);
@@ -1374,15 +1374,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseTagsSearch(string $input): string {
 	private function parseTagsSearch(string $input): string {
 		if (preg_match_all('%#(?P<search>/.*?(?<!\\\\)/[im]*)%', $input, $matches)) {
 		if (preg_match_all('%#(?P<search>/.*?(?<!\\\\)/[im]*)%', $input, $matches)) {
 			$this->tags_regex = $matches['search'];
 			$this->tags_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/#(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/#(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->tags = $matches['search'];
 			$this->tags = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/#(?P<search>[^\\s"]+)/', $input, $matches)) {
 		if (preg_match_all('/#(?P<search>[^\\s"]+)/', $input, $matches)) {
 			$this->tags = array_merge($this->tags ?? [], $matches['search']);
 			$this->tags = array_merge($this->tags ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->tags = self::removeEmptyValues($this->tags);
 		$this->tags = self::removeEmptyValues($this->tags);
 		if (empty($this->tags)) {
 		if (empty($this->tags)) {
@@ -1396,15 +1396,15 @@ class FreshRSS_Search implements \Stringable {
 	private function parseNotTagsSearch(string $input): string {
 	private function parseNotTagsSearch(string $input): string {
 		if (preg_match_all('%(?<=[\\s(]|^)[!-]#(?P<search>/.*?(?<!\\\\)/[im]*)%', $input, $matches)) {
 		if (preg_match_all('%(?<=[\\s(]|^)[!-]#(?P<search>/.*?(?<!\\\\)/[im]*)%', $input, $matches)) {
 			$this->not_tags_regex = $matches['search'];
 			$this->not_tags_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]#(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]#(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_tags = $matches['search'];
 			$this->not_tags = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]#(?P<search>[^\\s"]+)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-]#(?P<search>[^\\s"]+)/', $input, $matches)) {
 			$this->not_tags = array_merge($this->not_tags ?? [], $matches['search']);
 			$this->not_tags = array_merge($this->not_tags ?? [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_tags = self::removeEmptyValues($this->not_tags);
 		$this->not_tags = self::removeEmptyValues($this->not_tags);
 		if (empty($this->not_tags)) {
 		if (empty($this->not_tags)) {
@@ -1427,13 +1427,11 @@ class FreshRSS_Search implements \Stringable {
 		}
 		}
 		if (preg_match_all('#(?<=[\\s(]|^)(?<![!-\\\\])(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)(?<![!-\\\\])(?P<search>/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->search_regex = $matches['search'];
 			$this->search_regex = $matches['search'];
-			//TODO: Replace all those str_replace with PREG_OFFSET_CAPTURE
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)(?<![!-\\\\])(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)(?<![!-\\\\])(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->search = $matches['search'];
 			$this->search = $matches['search'];
-			//TODO: Replace all those str_replace with PREG_OFFSET_CAPTURE
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		return $input;
 		return $input;
 	}
 	}
@@ -1462,11 +1460,11 @@ class FreshRSS_Search implements \Stringable {
 		}
 		}
 		if (preg_match_all('#(?<=[\\s(]|^)[!-](?P<search>(?<!\\\\)/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 		if (preg_match_all('#(?<=[\\s(]|^)[!-](?P<search>(?<!\\\\)/.*?(?<!\\\\)/[im]*)#', $input, $matches)) {
 			$this->not_search_regex = $matches['search'];
 			$this->not_search_regex = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-](?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-](?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
 			$this->not_search = $matches['search'];
 			$this->not_search = $matches['search'];
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$input = self::cleanSearch($input);
 		$input = self::cleanSearch($input);
 		if ($input === '') {
 		if ($input === '') {
@@ -1474,7 +1472,7 @@ class FreshRSS_Search implements \Stringable {
 		}
 		}
 		if (preg_match_all('/(?<=[\\s(]|^)[!-](?P<search>[^\\s]+)/', $input, $matches)) {
 		if (preg_match_all('/(?<=[\\s(]|^)[!-](?P<search>[^\\s]+)/', $input, $matches)) {
 			$this->not_search = array_merge(is_array($this->not_search) ? $this->not_search : [], $matches['search']);
 			$this->not_search = array_merge(is_array($this->not_search) ? $this->not_search : [], $matches['search']);
-			$input = str_replace($matches[0], '', $input);
+			$input = strtr($input, array_fill_keys($matches[0], ''));
 		}
 		}
 		$this->not_search = self::removeEmptyValues($this->not_search);
 		$this->not_search = self::removeEmptyValues($this->not_search);
 		return $input;
 		return $input;

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

@@ -66,6 +66,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
 			['word1 intitle:"word2 word3"', ['word2 word3'], ['word1']],
 			['word1 intitle:"word2 word3"', ['word2 word3'], ['word1']],
 			["word1 intitle:'word2 word3'", ['word2 word3'], ['word1']],
 			["word1 intitle:'word2 word3'", ['word2 word3'], ['word1']],
 			['intitle:word1 intitle:word2', ['word1', 'word2'], null],
 			['intitle:word1 intitle:word2', ['word1', 'word2'], null],
+			['intitle:word1 intitle:word10', ['word1', 'word10'], null],
 			['intitle: word1 word2', null, ['word1', 'word2']],
 			['intitle: word1 word2', null, ['word1', 'word2']],
 			['intitle:123', ['123'], null],
 			['intitle:123', ['123'], null],
 			['intitle:"word1 word2" word3"', ['word1 word2'], ['word3"']],
 			['intitle:"word1 word2" word3"', ['word1 word2'], ['word3"']],
@@ -125,6 +126,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
 			['word1 author:"word2 word3"', ['word2 word3'], ['word1']],
 			['word1 author:"word2 word3"', ['word2 word3'], ['word1']],
 			["word1 author:'word2 word3'", ['word2 word3'], ['word1']],
 			["word1 author:'word2 word3'", ['word2 word3'], ['word1']],
 			['author:word1 author:word2', ['word1', 'word2'], null],
 			['author:word1 author:word2', ['word1', 'word2'], null],
+			['author:word1 author:word10', ['word1', 'word10'], null],
 			['author: word1 word2', null, ['word1', 'word2']],
 			['author: word1 word2', null, ['word1', 'word2']],
 			['author:123', ['123'], null],
 			['author:123', ['123'], null],
 			['author:"word1 word2" word3"', ['word1 word2'], ['word3"']],
 			['author:"word1 word2" word3"', ['word1 word2'], ['word3"']],
@@ -158,6 +160,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
 			['inurl:word1 word2', ['word1'], ['word2']],
 			['inurl:word1 word2', ['word1'], ['word2']],
 			['inurl:"word1 word2"', ['word1 word2'], null],
 			['inurl:"word1 word2"', ['word1 word2'], null],
 			['inurl:word1 word2 inurl:word3', ['word1', 'word3'], ['word2']],
 			['inurl:word1 word2 inurl:word3', ['word1', 'word3'], ['word2']],
+			['inurl:word1 inurl:word10', ['word1', 'word10'], null],
 			["inurl:word1 'word2 word3' word4", ['word1'], ['word2 word3', 'word4']],
 			["inurl:word1 'word2 word3' word4", ['word1'], ['word2 word3', 'word4']],
 			['inurl:word1+word2', ['word1+word2'], null],
 			['inurl:word1+word2', ['word1+word2'], null],
 		];
 		];
@@ -263,6 +266,8 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
 			['#word1 word2', ['word1'], ['word2']],
 			['#word1 word2', ['word1'], ['word2']],
 			['#"word1 word2"', ['word1 word2'], null],
 			['#"word1 word2"', ['word1 word2'], null],
 			['#word1 #word2', ['word1', 'word2'], null],
 			['#word1 #word2', ['word1', 'word2'], null],
+			['#word1 #word10', ['word1', 'word10'], null],
+			['#word10 #word1', ['word10', 'word1'], null],
 			["#word1 'word2 word3' word4", ['word1'], ['word2 word3', 'word4']],
 			["#word1 'word2 word3' word4", ['word1'], ['word2 word3', 'word4']],
 			['#word1+word2', ['word1 word2'], null]
 			['#word1+word2', ['word1 word2'], null]
 		];
 		];
@@ -678,12 +683,38 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
 				'(e.content ~ ?)',
 				'(e.content ~ ?)',
 				['^(ab|cd)']
 				['^(ab|cd)']
 			],
 			],
+			[
+				'!e:9 !e:90 !f:1 !f:10 !c:2 !c:20',
+				'(e.id NOT IN (?,?) AND e.id_feed NOT IN (?,?) AND e.id_feed NOT IN (SELECT f.id FROM `_feed` f WHERE f.category IN (?,?)))',
+				['9', '90', 1, 10, 2, 20]
+			],
+			[
+				'!intitle:word1 !intitle:word10',
+				'(e.title NOT LIKE ? AND e.title NOT LIKE ?)',
+				['%word1%', '%word10%']
+			],
 			[
 			[
 				'L:1 L:2',
 				'L:1 L:2',
 				'(e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)) AND ' .
 				'(e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)) AND ' .
 					'e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)))',
 					'e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)))',
 				[1, 2]
 				[1, 2]
 			],
 			],
+			[
+				'e:1 e:10',
+				'(e.id IN (?,?))',
+				['1', '10']
+			],
+			[
+				'f:1 f:10 c:2 c:20',
+				'(e.id_feed IN (?,?) AND e.id_feed IN (SELECT f.id FROM `_feed` f WHERE f.category IN (?,?)))',
+				[1, 10, 2, 20]
+			],
+			[
+				'L:1 L:10',
+				'(e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)) AND ' .
+					'e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)))',
+				[1, 10]
+			],
 			[
 			[
 				'L:1,2',
 				'L:1,2',
 				'(e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?,?)))',
 				'(e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?,?)))',