@@ -1335,10 +1335,12 @@ public function get_evaluated_answers(): array {
13351335 */
13361336 private static function wrap_algebraic_formulas_in_quotes (array $ formulas ): array {
13371337 foreach ($ formulas as &$ formula ) {
1338- // If the formula is aready wrapped in quotes (e. g. after an earlier call to this
1339- // function), there is nothing to do.
1338+ // If the formula is aready wrapped in quotes, we throw an Exception, because that
1339+ // should not happen. It will happen, if the student puts quotes around their response, but
1340+ // we want that to be graded wrong. The exception will be caught and dealt with upstream,
1341+ // so we do not need to be more precise.
13401342 if (preg_match ('/^\"[^\"]*\"$/ ' , $ formula )) {
1341- continue ;
1343+ throw new Exception () ;
13421344 }
13431345
13441346 $ formula = '" ' . $ formula . '" ' ;
@@ -1495,7 +1497,12 @@ public function grade(array $response, bool $finalsubmit = false): array {
14951497 // formulas, we must wrap the answers in quotes before we move on. Also, we reset the conversion
14961498 // factor, because it is not needed for algebraic answers.
14971499 if ($ isalgebraic ) {
1498- $ response = self ::wrap_algebraic_formulas_in_quotes ($ response );
1500+ try {
1501+ $ response = self ::wrap_algebraic_formulas_in_quotes ($ response );
1502+ } catch (Throwable $ t ) {
1503+ // TODO: convert to non-capturing catch.
1504+ return ['answer ' => 0 , 'unit ' => $ unitcorrect ];
1505+ }
14991506 $ conversionfactor = 1 ;
15001507 }
15011508
0 commit comments