Skip to content

Commit

Permalink
Ensure fileName is not empty in WebworkWebservice.
Browse files Browse the repository at this point in the history
When rendering a problem via WebworkWebservice, only use $rh->{fileName}
if it is defined and not empty.  This ensures that the
$ProblemRecord->source_file is set so images and other assets can be
found relative to the original file name when previewing, checking,
or showing correct answers in the PGProblemEditor rendered problem.

This fixes openwebwork#2556.
  • Loading branch information
somiaj committed Sep 15, 2024
1 parent 72fc97e commit 005d087
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/WebworkWebservice/RenderProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,16 @@ async sub renderProblem {
my $r_problem_source;
if ($rh->{problemSource}) {
$r_problem_source = \(decode_utf8_base64($rh->{problemSource}) =~ tr/\r/\n/r);
$problemRecord->source_file(defined $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
$problemRecord->source_file(defined $rh->{fileName}
&& $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
} elsif ($rh->{rawProblemSource}) {
$r_problem_source = \$rh->{rawProblemSource};
$problemRecord->source_file(defined $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
$problemRecord->source_file(defined $rh->{fileName}
&& $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
} elsif ($rh->{uriEncodedProblemSource}) {
$r_problem_source = \(url_unescape($rh->{uriEncodedProblemSource}));
$problemRecord->source_file(defined $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
$problemRecord->source_file(defined $rh->{fileName}
&& $rh->{fileName} ? $rh->{fileName} : $rh->{sourceFilePath});
} elsif (defined $rh->{sourceFilePath} && $rh->{sourceFilePath} =~ /\S/) {
$problemRecord->source_file($rh->{sourceFilePath});
$r_problem_source = \(readFile($ce->{courseDirs}{templates} . '/' . $rh->{sourceFilePath}));
Expand Down

0 comments on commit 005d087

Please sign in to comment.