Skip to content

Commit

Permalink
System: fixed issue with search terms containing a : (special charact…
Browse files Browse the repository at this point in the history
…er) (#1904)

Co-authored-by: Ali Alam <[email protected]>
  • Loading branch information
ali-ichk and Ali Alam authored Feb 26, 2025
1 parent ef4d28d commit 9e1ef95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/Domain/QueryCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function searchBy($column, $text = null)
*/
private function applyAdvancedSearchFilters($text)
{
$text = preg_replace_callback('/(\w*\:[\w\-]*|(?:"[^"]*"))+/', function ($matches) {
$text = preg_replace_callback('/(\w*\:\:[\w\-]*|(?:"[^"]*"))+/', function ($matches) {
$this->filterBy($matches[0]);
return '';
}, $text);
Expand Down Expand Up @@ -309,8 +309,8 @@ public function filterBy($name, $value = null)
{
if (empty($name)) return $this;

if (stripos($name, ':') !== false) {
list($name, $value) = array_pad(explode(':', $name, 2), 2, '');
if (stripos($name, '::') !== false) {
list($name, $value) = array_pad(explode('::', $name, 2), 2, '');
$value = str_replace('"', '', $value);
}

Expand Down Expand Up @@ -364,7 +364,7 @@ public function getFilterValue($name)
public function getFilterString()
{
return implode(' ', array_map(function($value, $name) {
return stripos($value, ' ') !== false ? $name.':"'.$value .'"' : $name.':'.$value;
return stripos($value, ' ') !== false ? $name.'::"'.$value .'"' : $name.'::'.$value;
}, $this->criteria['filterBy'], array_keys($this->criteria['filterBy'])));
}

Expand Down
20 changes: 10 additions & 10 deletions tests/unit/Domain/QueryCriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,28 @@ public function testCanGetAllSearches()

public function testCanAddFilterToSearchString()
{
$this->criteria->searchBy('columnName', 'foo bar active:Y');
$this->criteria->searchBy('columnName', 'foo bar active::Y');

$this->assertTrue($this->criteria->hasFilter('active', 'Y'));
if (method_exists($this, 'assertStringNotContainsString')) {
// for newer phpunit versions
$this->assertStringNotContainsString('active:Y', $this->criteria->getSearchText());
$this->assertStringNotContainsString('active::Y', $this->criteria->getSearchText());
} else {
// for older phpunit versions
$this->assertNotContains('active:Y', $this->criteria->getSearchText());
$this->assertNotContains('active::Y', $this->criteria->getSearchText());
}
}

public function testCanFilterByString()
{
$this->criteria->filterBy('foo:bar');
$this->criteria->filterBy('foo::bar');

$this->assertTrue($this->criteria->hasFilter('foo', 'bar'));
}

public function testCanFilterByQuotedString()
{
$this->criteria->filterBy('foo:"bar baz"');
$this->criteria->filterBy('foo::"bar baz"');

$this->assertTrue($this->criteria->hasFilter('foo', 'bar baz'));
}
Expand All @@ -186,24 +186,24 @@ public function testCanCheckIfCriteriaHasFilters()
{
$this->assertFalse($this->criteria->hasFilter());

$this->criteria->filterBy('foo:bar');
$this->criteria->filterBy('foo::bar');

$this->assertTrue($this->criteria->hasFilter());
}

public function testCanGetAllFilters()
{
$this->criteria->filterBy('foo:bar');
$this->criteria->filterBy('foo::bar');

$this->assertTrue(is_array($this->criteria->getFilterBy()));
}

public function testCanGetAllFiltersAsString()
{
$this->criteria->filterBy('foo:bar');
$this->criteria->filterBy('baz:"some thing"');
$this->criteria->filterBy('foo::bar');
$this->criteria->filterBy('baz::"some thing"');

$this->assertEquals('foo:bar baz:"some thing"', $this->criteria->getFilterString());
$this->assertEquals('foo::bar baz::"some thing"', $this->criteria->getFilterString());
}

public function testCanSortAscending()
Expand Down

0 comments on commit 9e1ef95

Please sign in to comment.