@@ -71,14 +71,8 @@ class FreshRSS_Search {
7171 /** @var array<string>|null */
7272 private $ not_search ;
7373
74- /**
75- * @param string|null $input
76- */
77- public function __construct (?string $ input ) {
78- $ input = (string )$ input ;
79- if ($ input === '' ) {
80- return ;
81- }
74+ public function __construct (string $ input ) {
75+ $ input = self ::cleanSearch ($ input );
8276 $ this ->raw_input = $ input ;
8377
8478 $ input = $ this ->parseNotEntryIds ($ input );
@@ -443,6 +437,9 @@ private function parseIntitleSearch(string $input): string {
443437 $ input = str_replace ($ matches [0 ], '' , $ input );
444438 }
445439 $ this ->intitle = self ::removeEmptyValues ($ this ->intitle );
440+ if (empty ($ this ->intitle )) {
441+ $ this ->intitle = null ;
442+ }
446443 return $ input ;
447444 }
448445
@@ -456,6 +453,9 @@ private function parseNotIntitleSearch(string $input): string {
456453 $ input = str_replace ($ matches [0 ], '' , $ input );
457454 }
458455 $ this ->not_intitle = self ::removeEmptyValues ($ this ->not_intitle );
456+ if (empty ($ this ->not_intitle )) {
457+ $ this ->not_intitle = null ;
458+ }
459459 return $ input ;
460460 }
461461
@@ -474,6 +474,9 @@ private function parseAuthorSearch(string $input): string {
474474 $ input = str_replace ($ matches [0 ], '' , $ input );
475475 }
476476 $ this ->author = self ::removeEmptyValues ($ this ->author );
477+ if (empty ($ this ->author )) {
478+ $ this ->author = null ;
479+ }
477480 return $ input ;
478481 }
479482
@@ -487,6 +490,9 @@ private function parseNotAuthorSearch(string $input): string {
487490 $ input = str_replace ($ matches [0 ], '' , $ input );
488491 }
489492 $ this ->not_author = self ::removeEmptyValues ($ this ->not_author );
493+ if (empty ($ this ->not_author )) {
494+ $ this ->not_author = null ;
495+ }
490496 return $ input ;
491497 }
492498
@@ -498,17 +504,17 @@ private function parseInurlSearch(string $input): string {
498504 if (preg_match_all ('/\binurl:(?P<search>[^\s]*)/ ' , $ input , $ matches )) {
499505 $ this ->inurl = $ matches ['search ' ];
500506 $ input = str_replace ($ matches [0 ], '' , $ input );
507+ $ this ->inurl = self ::removeEmptyValues ($ this ->inurl );
501508 }
502- $ this ->inurl = self ::removeEmptyValues ($ this ->inurl );
503509 return $ input ;
504510 }
505511
506512 private function parseNotInurlSearch (string $ input ): string {
507513 if (preg_match_all ('/(?<=\s|^)[!-]inurl:(?P<search>[^\s]*)/ ' , $ input , $ matches )) {
508514 $ this ->not_inurl = $ matches ['search ' ];
509515 $ input = str_replace ($ matches [0 ], '' , $ input );
516+ $ this ->not_inurl = self ::removeEmptyValues ($ this ->not_inurl );
510517 }
511- $ this ->not_inurl = self ::removeEmptyValues ($ this ->not_inurl );
512518 return $ input ;
513519 }
514520
@@ -574,19 +580,19 @@ private function parseTagsSearch(string $input): string {
574580 if (preg_match_all ('/#(?P<search>[^\s]+)/ ' , $ input , $ matches )) {
575581 $ this ->tags = $ matches ['search ' ];
576582 $ input = str_replace ($ matches [0 ], '' , $ input );
583+ $ this ->tags = self ::removeEmptyValues ($ this ->tags );
584+ $ this ->tags = self ::decodeSpaces ($ this ->tags );
577585 }
578- $ this ->tags = self ::removeEmptyValues ($ this ->tags );
579- $ this ->tags = self ::decodeSpaces ($ this ->tags );
580586 return $ input ;
581587 }
582588
583589 private function parseNotTagsSearch (string $ input ): string {
584590 if (preg_match_all ('/(?<=\s|^)[!-]#(?P<search>[^\s]+)/ ' , $ input , $ matches )) {
585591 $ this ->not_tags = $ matches ['search ' ];
586592 $ input = str_replace ($ matches [0 ], '' , $ input );
593+ $ this ->not_tags = self ::removeEmptyValues ($ this ->not_tags );
594+ $ this ->not_tags = self ::decodeSpaces ($ this ->not_tags );
587595 }
588- $ this ->not_tags = self ::removeEmptyValues ($ this ->not_tags );
589- $ this ->not_tags = self ::decodeSpaces ($ this ->not_tags );
590596 return $ input ;
591597 }
592598
@@ -651,8 +657,8 @@ private function parseNotSearch(string $input): string {
651657 */
652658 private static function cleanSearch (string $ input ): string {
653659 $ input = preg_replace ('/\s+/ ' , ' ' , $ input );
654- if ($ input === null ) {
655- $ input = '' ;
660+ if (! is_string ( $ input) ) {
661+ return '' ;
656662 }
657663 return trim ($ input );
658664 }
0 commit comments