Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private function searchCustomPages(string $searchTerm, bool $allLanguages = true
// Escape LIKE metacharacters (%, _) to prevent wildcard injection
$escapedWord = str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $word);
$searchConditions[] = sprintf(
"(page_title LIKE '%%%s%%' ESCAPE '\\' OR content LIKE '%%%s%%' ESCAPE '\\')",
"(page_title LIKE '%%%s%%' ESCAPE '\\\\' OR content LIKE '%%%s%%' ESCAPE '\\\\')",
$escapedWord,
$escapedWord,
);
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Search/Database/PdoPgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function search(string $searchTerm): mixed
FROM
%s %s %s %s
WHERE
(%s) ILIKE ('%%%s%%') ESCAPE '\\'
(%s) ILIKE ('%%%s%%') ESCAPE '\\\\'
%s
%s",
$columns,
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Search/SearchDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function getMatchClause(string $searchTerm = ''): string
}

$where = sprintf(
"%s%s LIKE '%%%s%%' ESCAPE '\\'",
"%s%s LIKE '%%%s%%' ESCAPE '\\\\'",
$where,
$this->matchingColumns[$j],
self::escapeLikeWildcards($this->configuration->getDb()->escape($keys[$i])),
Expand Down
6 changes: 3 additions & 3 deletions tests/phpMyFAQ/Search/SearchDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testGetMatchClause()
{
$this->searchDatabase->setMatchingColumns(['faqdata.author']);
$this->assertEquals(
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\')",
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\\\')",
$this->searchDatabase->getMatchClause('Thorsten'),
);
$this->assertIsString($this->searchDatabase->getMatchClause('Thorsten'));
Expand All @@ -159,7 +159,7 @@ public function testGetMatchClauseWithTwoSearchTerms()
{
$this->searchDatabase->setMatchingColumns(['faqdata.author']);
$this->assertEquals(
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\') OR (faqdata.author LIKE '%Rinne%' ESCAPE '\\')",
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\\\') OR (faqdata.author LIKE '%Rinne%' ESCAPE '\\\\')",
$this->searchDatabase->getMatchClause('Thorsten Rinne'),
);
$this->assertIsString($this->searchDatabase->getMatchClause('Thorsten'));
Expand All @@ -169,7 +169,7 @@ public function testGetMatchClauseWithTwoColumns()
{
$this->searchDatabase->setMatchingColumns(['faqdata.author', 'faqdata.thema']);
$this->assertEquals(
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\' OR faqdata.thema LIKE '%Thorsten%' ESCAPE '\\')",
" (faqdata.author LIKE '%Thorsten%' ESCAPE '\\\\' OR faqdata.thema LIKE '%Thorsten%' ESCAPE '\\\\')",
$this->searchDatabase->getMatchClause('Thorsten'),
);
$this->assertIsString($this->searchDatabase->getMatchClause('Thorsten'));
Expand Down
Loading