Skip to content

Commit

Permalink
Fix for #2427: added search term encoding & escaping to match the for…
Browse files Browse the repository at this point in the history
…mat of the content in `bolt_field_translation`.
  • Loading branch information
EmilePerron authored and bobdenotter committed Feb 27, 2021
1 parent dee564f commit f485fdc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Repository/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ public function searchNaive(string $searchTerm, int $page, int $amountPerPage, C
$connection = $qb->getEntityManager()->getConnection();
[$where] = JsonHelper::wrapJsonFunction('t.value', $searchTerm, $connection);

// The search term must match the format of the content in the database
// Therefore, it is JSON encoded and escaped with backslashes
$encodedSearchTerm = addslashes(trim(json_encode($searchTerm), '"'));

$qb->addSelect('f')
->innerJoin('content.fields', 'f')
->innerJoin('f.translations', 't')
->andWhere($qb->expr()->like($where, ':search'))
->setParameter('search', '%' . $searchTerm . '%');
->setParameter('search', '%' . $encodedSearchTerm . '%');

// These are the ID's of content we need.
$ids = array_column($qb->getQuery()->getArrayResult(), 'id');
Expand Down

0 comments on commit f485fdc

Please sign in to comment.