From 5dbfbc82cf7948395ddc2f31aa49abf1020ccef9 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 22 Nov 2013 11:29:56 +0000 Subject: [PATCH] MDL-43000 shortanswer qtype: handle patterns with many *s Teachers were typing patterns like ************************************************************ which translates into a pattern like .*.*.*.*, which is very inefficient to try to match, althought it is equivalent ot a single .*. At a certain point preg was just giving up. Since people actually do this, we should simplify the regex by treating runs of * like a single *. --- question/type/shortanswer/question.php | 6 ++++-- question/type/shortanswer/tests/question_test.php | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/question/type/shortanswer/question.php b/question/type/shortanswer/question.php index df200fff3f1..b1c69ad08d5 100644 --- a/question/type/shortanswer/question.php +++ b/question/type/shortanswer/question.php @@ -92,8 +92,10 @@ class qtype_shortanswer_question extends question_graded_by_strategy $pattern = self::safe_normalize($pattern); $string = self::safe_normalize($string); - // Break the string on non-escaped asterisks. - $bits = preg_split('/(?assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( + '', '**********************************************************************', false)); + } + public function test_is_complete_response() { $question = test_question_maker::make_question('shortanswer');