diff --git a/src/TermBuilder.php b/src/TermBuilder.php index 109e832..c328b79 100644 --- a/src/TermBuilder.php +++ b/src/TermBuilder.php @@ -10,7 +10,7 @@ public static function terms($search) // Remove every boolean operator (+, -, > <, ( ), ~, *, ", @distance) from the search query // else we will break the MySQL query. - $search = rtrim(preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $search)); + $search = trim(preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $search)); $terms = collect(preg_split('/[\s,]+/', $search)); diff --git a/tests/TermBuilderTest.php b/tests/TermBuilderTest.php index 16bc3f1..975b92f 100644 --- a/tests/TermBuilderTest.php +++ b/tests/TermBuilderTest.php @@ -17,6 +17,18 @@ public function test_termbuilder_builds_terms_array() $this->assertCount(0, $diff); } + public function test_termbuilder_does_not_build_empty_terms() + { + global $configReturn; + $configReturn = false; + + $termsResult = ['']; + $terms = TermBuilder::terms(implode(' ', $termsResult)); + $termsResultWithoutSpecialChars = ['hi', 'im', 'a', 'few', 'terms']; + $diff = $terms->diff($termsResultWithoutSpecialChars); + $this->assertCount(0, $diff); + } + public function test_termbuilder_builds_terms_array_with_wildcard() { global $configReturn;