From afbb1b7fb5fcb7a44b301ca175c5488b14291688 Mon Sep 17 00:00:00 2001 From: Arnaud Trouve Date: Fri, 17 Mar 2017 08:29:49 +0100 Subject: [PATCH] MDL-58257 course: fix search containing a hyphen In case a hyphen (-) was preceded and followed by spaces, the pattern for the "not regex" was empty causing an empty response from the database --- lib/datalib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datalib.php b/lib/datalib.php index 43e2411beb3..eb2bf9c0ba0 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -787,7 +787,7 @@ function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$total $searchcond[] = "$concat $REGEXP :ss$i"; $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)"; - } else if (substr($searchterm,0,1) == "-") { + } else if ((substr($searchterm,0,1) == "-") && (core_text::strlen($searchterm) > 1)) { $searchterm = trim($searchterm, '+-'); $searchterm = preg_quote($searchterm, '|'); $searchcond[] = "$concat $NOTREGEXP :ss$i";