Skip to content

Commit 61c420a

Browse files
GuillaumeValadasgarvinhickingfe-hicking
authored
Fix search issue with special characters, and escape them in SQL. #844 (#846)
* Fix search issue with special characters, and escape them in SQL. #844 * Update functions_entries.inc.php Co-authored-by: Garvin Hicking <38074677+fe-hicking@users.noreply.github.com> * Update functions_entries.inc.php Co-authored-by: Garvin Hicking <38074677+fe-hicking@users.noreply.github.com> * #844 Simplify code removing If statement because we escape term search anyway + change alias to mysqli_real_escape_string * Issue #844 Bring back if statement to switch over boolean mode or not + change regex to only catch BOOLEAN Operator that prefix a word * Update regex boolean mode is trigger only on operator followed by words * Fix typo on regex * #844 add another regex to avoid boolean operator alone that could lead to error --------- Co-authored-by: Garvin Hicking <blog@garv.in> Co-authored-by: Garvin Hicking <38074677+fe-hicking@users.noreply.github.com>
1 parent e648571 commit 61c420a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/db/mysqli.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function serendipity_db_matched_rows() {
189189
*/
190190
function serendipity_db_escape_string($string) {
191191
global $serendipity;
192-
return mysqli_escape_string($serendipity['dbConn'], $string);
192+
return mysqli_real_escape_string($serendipity['dbConn'], $string);
193193
}
194194

195195
/**

include/functions_entries.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ function &serendipity_searchEntries($term, $limit = '', $searchresults = '') {
882882
$cond['distinct'] = '';
883883
$term = str_replace('&quot;', '"', $term);
884884
$relevance_enabled = true;
885-
if (preg_match('@["\+\-\*~<>\(\)]+@', $term)) {
885+
if (preg_match('@[\+\-\*~<>\(\)"].[\S]*@', $term) && preg_match('@\s*[\+\-\*~<>\(\)]\s*$@', $term) === 0 ) {
886886
$cond['find_part'] = "MATCH(title,body,extended) AGAINST('$term' IN BOOLEAN MODE)";
887887
} else {
888888
$cond['find_part'] = "MATCH(title,body,extended) AGAINST('$term')";

0 commit comments

Comments
 (0)