Shortanswers are not more robust when * wildcards being used
authormoodler <moodler>
Tue, 27 Jul 2004 13:16:50 +0000 (13:16 +0000)
committermoodler <moodler>
Tue, 27 Jul 2004 13:16:50 +0000 (13:16 +0000)
mod/quiz/questiontypes/shortanswer/questiontype.php

index dd826fc0018f69a7e7ff09e76aff34bacdca1574..9a9e93242d3a01b56e5cdc0c717bebae4e2823e9 100644 (file)
@@ -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;
                         }