diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 4f9d62ea..e798aeb6 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -944,12 +944,16 @@ class Image $negative_tag_id_array = []; foreach ($tag_conditions as $tq) { + $sq = " + SELECT id + FROM tags + WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag) + "; + if ($database->get_driver_name() === DatabaseDriver::SQLITE) { + $sq .= "ESCAPE '\\'"; + } $tag_ids = $database->get_col( - $database->scoreql_to_sql(" - SELECT id - FROM tags - WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag) - "), + $database->scoreql_to_sql($sq), ["tag" => Tag::sqlify($tq->tag)] ); diff --git a/core/imageboard/tag.php b/core/imageboard/tag.php index ddce54f6..6efbe328 100644 --- a/core/imageboard/tag.php +++ b/core/imageboard/tag.php @@ -103,6 +103,10 @@ class Tag public static function sqlify(string $term): string { + global $database; + if ($database->get_driver_name() === DatabaseDriver::SQLITE) { + $term = str_replace('\\', '\\\\', $term); + } $term = str_replace('_', '\_', $term); $term = str_replace('%', '\%', $term); $term = str_replace('*', '%', $term);