Skip to content

Commit 3c12ffd

Browse files
committed
MDL-76966 assignfeedback_editpdf: Perform escapeshellarg without pageno
1 parent 15557a5 commit 3c12ffd

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

mod/assign/feedback/editpdf/classes/pdf.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,9 @@ private function get_gs_command_for_image(int $pageno, string $imagefile): strin
694694
$firstpage = $pagenoinc;
695695
$lastpage = $pagenoinc;
696696
} else {
697-
// Convert all pages at once.
698-
$imagefilearg = \escapeshellarg($imagefile . '%d.png');
697+
// Convert all pages at once. Ensure that %d is not replaced by escapeshellarg on Windows systems.
698+
$imagefilearg = \escapeshellarg($imagefile);
699+
$imagefilearg = substr($imagefilearg, 0, -1) . '%d.png' . substr($imagefilearg, -1);
699700
$firstpage = 1;
700701
$lastpage = $this->pagecount;
701702
}

mod/assign/feedback/editpdf/tests/feedback_test.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,15 @@ public function test_document_services(): void {
246246
$this->assertEquals($combinedpdf->get_contenthash(), document_services::BLANK_PDF_HASH);
247247

248248
// Generate page images and verify that the combined pdf has been replaced.
249-
document_services::get_page_images_for_attempt($assign, $student->id, -1);
249+
$pageimages = document_services::get_page_images_for_attempt($assign, $student->id, -1);
250250
$combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename);
251251
$this->assertNotEquals($combinedpdf->get_contenthash(), document_services::BLANK_PDF_HASH);
252252

253+
// Verify that the file name contains the page number from Ghostscript.
254+
foreach ($pageimages as $index => $image) {
255+
$this->assertTrue(str_contains($image->get_filename(), "page{$index}"));
256+
}
257+
253258
$notempty = page_editor::has_annotations_or_comments($grade->id, false);
254259
$this->assertFalse($notempty);
255260

0 commit comments

Comments
 (0)