Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bad regular expression logic in short answer

  • Loading branch information...
commit cc03ed4016999d7d2c110ede4c09ecbf04cd0c92 1 parent b435823
moodler authored
Showing with 20 additions and 12 deletions.
  1. +20 −12 mod/quiz/lib.php
32 mod/quiz/lib.php
View
@@ -1846,25 +1846,33 @@ function quiz_grade_attempt_question_result($question,
$correct[] = $answer->answer;
}
if (!$answer->usecase) { // Don't compare case
- $answer->answer = strtolower($answer->answer);
- $question->answer = strtolower($question->answer);
+ $answer->answer = moodle_strtolower($answer->answer);
+ $question->answer = moodle_strtolower($question->answer);
}
$potentialgrade = (float)$answer->fraction * $question->grade;
- if ($potentialgrade >= $grade and (strpos(' '.$answer->answer, '*'))) {
- $answer->answer = str_replace('\*','@@@@@@',$answer->answer);
- $answer->answer = str_replace('*','.*',$answer->answer);
- $answer->answer = str_replace('@@@@@@', '\*',$answer->answer);
- $answer->answer = str_replace('+', '\+',$answer->answer);
- if (eregi('^'.$answer->answer.'$', $question->answer)) {
+ if ($potentialgrade >= $grade) {
+ if ((strpos(' '.$answer->answer, '*'))) {
+ $search = array('\\', '+', '(', ')', '[', ']', '-');
+ $replace = array('\\\\', '\+', '\(', '\)', '\[', '\]', '\-');
+
+ $answer->answer = str_replace('\*','@@@@@@',$answer->answer);
+ $answer->answer = str_replace('*','.*',$answer->answer);
+
+ $answer->answer = str_replace($search, $replace, $answer->answer);
+
+ $answer->answer = str_replace('@@@@@@', '\*',$answer->answer);
+
+ if (eregi('^'.$answer->answer.'$', $question->answer)) {
+ $feedback[0] = $answer->feedback;
+ $grade = $potentialgrade;
+ }
+
+ } else if ($answer->answer == $question->answer) {
$feedback[0] = $answer->feedback;
$grade = $potentialgrade;
}
-
- } else if ($answer->answer == $question->answer) {
- $feedback[0] = $answer->feedback;
- $grade = $potentialgrade;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.