Skip to content

Commit 3b42928

Browse files
committed
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.
1 parent daff8af commit 3b42928

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/AnswerHash.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ sub input { #$rh_ans->input('foo') is a synonym for $rh_ans->{student_ans}='f
252252
sub score {
253253
my $self = shift;
254254
my $score = shift;
255-
$self->{score} = $score if defined($score);
255+
$self->{score} = $score || 0 if defined($score);
256256
$self->{score};
257257
}
258258

lib/Value/AnswerChecker.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ sub cmp_list_compare {
16961696
#
16971697
# Check for empty lists
16981698
#
1699-
if (scalar(@correct) == 0) { $ans->score($m == 0); return }
1699+
if (scalar(@correct) == 0) { $ans->score($m == 0 ? 1 : 0); return }
17001700

17011701
#
17021702
# Loop through student answers looking for correct ones

0 commit comments

Comments
 (0)