From 26997a1f82ccecbd7d32e04516401007aee43a73 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 27 Jul 2004 13:16:50 +0000 Subject: [PATCH] Shortanswers are not more robust when * wildcards being used --- mod/quiz/questiontypes/shortanswer/questiontype.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mod/quiz/questiontypes/shortanswer/questiontype.php b/mod/quiz/questiontypes/shortanswer/questiontype.php index dd826fc001..9a9e93242d 100644 --- a/mod/quiz/questiontypes/shortanswer/questiontype.php +++ b/mod/quiz/questiontypes/shortanswer/questiontype.php @@ -149,6 +149,11 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype { /// Determine ->answers[] $result->answers = array(); if ('' !== $response0) { + + /// These are things to protect in the strings when wildcards are used + $search = array('\\', '+', '(', ')', '[', ']', '-'); + $replace = array('\\\\', '\+', '\(', '\)', '\[', '\]', '\-'); + foreach ($answers as $answer) { $answer->answer = trim($answer->answer); // Just in case @@ -166,8 +171,9 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype { if (strpos(' '.$answer0, '*')) { $answer0 = str_replace('\*','@@@@@@',$answer0); $answer0 = str_replace('*','.*',$answer0); + $answer0 = str_replace($search, $replace, $answer0); $answer0 = str_replace('@@@@@@', '\*',$answer0); - $answer0 = str_replace('+', '\+',$answer0); + if (ereg('^'.$answer0.'$', $response0)) { $result->answers[$nameprefix] = $answer; } -- 2.39.5