From 3b87778fbb8bf7dc131b505dea0cf395f9f1d3b9 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 15 Jun 2018 19:24:23 +0930 Subject: [PATCH] =?UTF-8?q?Prevent=20@=20character=20used=20in=20searches?= =?UTF-8?q?=20from=20crashing=20MySQL=20=F0=9F=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Discussion/Search/Gambit/FulltextGambit.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Discussion/Search/Gambit/FulltextGambit.php b/src/Discussion/Search/Gambit/FulltextGambit.php index 52307d60d..81f5e5976 100644 --- a/src/Discussion/Search/Gambit/FulltextGambit.php +++ b/src/Discussion/Search/Gambit/FulltextGambit.php @@ -29,6 +29,10 @@ class FulltextGambit implements GambitInterface throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } + // The @ character crashes fulltext searches on InnoDB tables. + // See https://bugs.mysql.com/bug.php?id=74042 + $bit = str_replace('@', '*', $bit); + $search->getQuery() ->selectRaw('SUBSTRING_INDEX(GROUP_CONCAT(posts.id ORDER BY MATCH(posts.content) AGAINST (?) DESC), \',\', 1) as most_relevant_post_id', [$bit]) ->leftJoin('posts', 'posts.discussion_id', '=', 'discussions.id')