From 3b4292848022a8ccdd0d791809024288fc402d4d Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Wed, 17 Jan 2024 19:51:34 -0700 Subject: [PATCH] Ensure a false score is saved as 0 in AnswerHash. Somewhere in the Rendering.pm path, a boolean false score gets converted into an empty string, which can no longer be used in some numerical comparisons, as discussed in openwebwork/webwork2#2300. This fixes the case mentioned in the issue, and sets false values to 0 when setting the score in the AnswerHash to catch other possible cases. --- lib/AnswerHash.pm | 2 +- lib/Value/AnswerChecker.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnswerHash.pm b/lib/AnswerHash.pm index 06ffc11f5c..0a8d9f2146 100755 --- a/lib/AnswerHash.pm +++ b/lib/AnswerHash.pm @@ -252,7 +252,7 @@ sub input { #$rh_ans->input('foo') is a synonym for $rh_ans->{student_ans}='f sub score { my $self = shift; my $score = shift; - $self->{score} = $score if defined($score); + $self->{score} = $score || 0 if defined($score); $self->{score}; } diff --git a/lib/Value/AnswerChecker.pm b/lib/Value/AnswerChecker.pm index 7abbda7099..2ae6c1f6f9 100644 --- a/lib/Value/AnswerChecker.pm +++ b/lib/Value/AnswerChecker.pm @@ -1696,7 +1696,7 @@ sub cmp_list_compare { # # Check for empty lists # - if (scalar(@correct) == 0) { $ans->score($m == 0); return } + if (scalar(@correct) == 0) { $ans->score($m == 0 ? 1 : 0); return } # # Loop through student answers looking for correct ones