From 005d0878d92e68fb4eca20458063552e64bc64c1 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sun, 15 Sep 2024 13:22:48 -0600 Subject: [PATCH] Ensure fileName is not empty in WebworkWebservice. 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 #2556. --- lib/WebworkWebservice/RenderProblem.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/WebworkWebservice/RenderProblem.pm b/lib/WebworkWebservice/RenderProblem.pm index 8d38f82846..56d552fe57 100644 --- a/lib/WebworkWebservice/RenderProblem.pm +++ b/lib/WebworkWebservice/RenderProblem.pm @@ -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}));