Skip to content

Commit

Permalink
Merge pull request #1020 from drgrice1/bugfix/radiomultians-value-error
Browse files Browse the repository at this point in the history
Fix Value::Error calls in a checker for a RadioMultiAnswer object.
  • Loading branch information
pstaabp authored Feb 21, 2024
2 parents 931f9c5 + 1ab5813 commit 165622c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions macros/parsers/parserMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ sub perform_check {
$rh_ans->{isPreview} = $inputs->{previewAnswers}
|| ($inputs_{action} && $inputs->{action} =~ m/^Preview/);

Parser::Context->current(undef, $context); # change to multi-answer's context
my $flags = Value::contextSet($context, $self->cmp_contextFlags($ans)); # save old context flags
$context->{answerHash} = $rh_ans; # attach the answerHash
Parser::Context->current(undef, $context); # change to multi-answer's context
my $flags = Value::contextSet($context, $self->cmp_contextFlags($rh_ans)); # save old context flags
$context->{answerHash} = $rh_ans; # attach the answerHash
my @result = Value::cmp_compare([@correct], [@student], $self, $rh_ans);
Value::contextSet($context, %{$flags}); # restore context values
$context->{answerHash} = undef; # remove answerHash
Value::contextSet($context, %{$flags}); # restore context values
$context->{answerHash} = undef; # remove answerHash
if (!@result && $context->{error}{flag}) { $self->cmp_error($self->{ans}[0]); return 1 }

my $result = (scalar(@result) > 1 ? [@result] : $result[0] || 0);
Expand Down
14 changes: 12 additions & 2 deletions macros/parsers/parserRadioMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ sub check_string {
# supplied checker.
sub perform_check {
my ($self, $rh_ans) = @_;
$self->context->clearError;
my $context = $self->context;
$context->clearError;
my @correct;
my @student;
# The answers for all parts are sent to the grader. The answers in the incorrect parts from
Expand Down Expand Up @@ -565,8 +566,17 @@ sub perform_check {
$rh_ans->{isPreview} = $main::inputs_ref->{previewAnswers}
|| ($main::inputs_ref->{action} && $main::inputs_ref->{action} =~ m/^Preview/);
$self->{errorMessages} = [];

Parser::Context->current(undef, $context); # change to the radio multi answers's context
my $flags = Value::contextSet($context, $self->cmp_contextFlags($rh_ans)); # save old context flags
my $result = Value::cmp_compare([@correct], [@student], $self, $rh_ans);
if (!defined $result && $self->context->{error}{flag}) { $self->cmp_error($self->{ans}[0]); return 1; }
Value::contextSet($context, %{$flags}); # restore context values
$context->{answerHash} = undef; # remove answerHash

if (!defined $result && $self->context->{error}{flag}) {
$self->appendMessage($self->context->{error}{message});
return 1;
}
if (Value::matchNumber($result)) {
$rh_ans->score($result);
} else {
Expand Down

0 comments on commit 165622c

Please sign in to comment.