From ce4379973fa3c8efb2e825c1910c4a32d8761579 Mon Sep 17 00:00:00 2001 From: Arnaud Trouve Date: Tue, 14 Mar 2017 19:07:09 +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 96a940cf683..df48d6d8500 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";